#!/bin/bash
PROCESS=$1
log_found=`ps faux|grep -v grep|grep $PROCESS|awk '{print $2}'`
if [ "$log_found" == "" ]; then
echo "No process found"
else
echo "Open files:"
for PID in $log_found; do
#ls -l /proc/$PID/fd/ | awk '{print $NF;}'
ls -l /proc/$PID/fd/
done
fi
Monday, 11 June 2012
Check witch files a process has open
This script will output a list of the files that are open by a given process:
Labels:
Command Line,
Linux,
Scripting
Possibly Related Posts
Tuesday, 5 June 2012
Monitor a processes memory and cpu usage over time
To do this I use the following command:
watch -d -n 1 'ps -o "user pid cmd pcpu pmem rss" $(pgrep apache)'you can replace "apache" with the executable name of the process you want to monitor
Labels:
Command Line,
Linux,
Monitoring
Possibly Related Posts
Monday, 4 June 2012
locale: Cannot Set LC_ALL to default locale: No such file or directory
To solve this, first try using the command:
If you continue to get error messages and you are accessing a remote server, check if the default locale setting on your machine is supported by the remote box.
You can check the default locale setting with:
sudo locale-genif this does not work check with locale -a the locale you actually got on your system and make sure you have the locale in UTF-8 encoding for every language on your system, something like this:
$ locale -aAnd use the following command to generate it:
C
C.UTF-8
en_AG
en_AG.utf8
en_AU.utf8
en_BW.utf8
en_CA.utf8
en_DK.utf8
en_GB.utf8
en_HK.utf8
en_IE.utf8
en_IN
en_IN.utf8
en_NG
en_NG.utf8
en_NZ.utf8
en_PH.utf8
en_SG.utf8
en_US.utf8
en_ZA.utf8
en_ZM
en_ZM.utf8
en_ZW.utf8
POSIX
pt_BR.utf8
pt_PT.utf8
localedef -v -c -i en_US -f UTF-8 en_US.UTF-8(It's case sensitive as far as I remember, you actually have to use the resulting locale string literally.)
If you continue to get error messages and you are accessing a remote server, check if the default locale setting on your machine is supported by the remote box.
You can check the default locale setting with:
cat /etc/default/localewhich in my case returned:
LANG="en_US.UTF-8"In my case the default locale on my laptop was en_US.UTF-8, but the server was using en_GB.UTF-8 only. I solved this by adding en_US.UTF-8 to /etc/default/locale (via "dpkg-reconfigure locales").
Possibly Related Posts
Tuesday, 29 May 2012
List users with running processes
Show the unique list of users running processes on the system
ps haexo user | sort -uShow the unique list of users running processes on the system, prefixed by number of processes for that user
ps haexo user | sort | uniq -cSame than above, but sorted by the number of processes
ps haexo user | sort | uniq -c | sort -nr
Labels:
Command Line,
Linux,
Scripting
Possibly Related Posts
Tuesday, 22 May 2012
Export multiple schemas from Oracle
For the examples to work we must first create a directory object you can access. The directory object is only a pointer to a physical directory, creating it does not actually create the physical directory on the file system.
sqlplus / AS SYSDBAYou can use expdp like this
CREATE OR REPLACE DIRECTORY DUMP_DIR AS '/home/oracle/dumpdir/';
expdp "'/ as sysdba'" dumpfile=TEST.dmp directory=DUMP_DIR logfile=TEST.log schemas=test1,test2,test3,test4But if you want one separate file for each export, you can use a shell script like this:
#!/bin/bashNow run the script:
export_schema=$1
expdp "'/ as sysdba'" dumpfile=${export_schema}.dmp directory=DUMP_DIR logfile=${export_schema}.log schemas=${export_schema}
# end of script
exp_script.sh TEST1or
exp_script.sh TEST2Or if you prefer a one line script:
for export_schema in TEST1 TEST2 TEST3; do expdp "'/ as sysdba'" dumpfile=${export_schema}.dmp directory=DUMP_DIR logfile=${export_schema}.log schemas=${export_schema}; done;
Possibly Related Posts
Friday, 11 May 2012
Map Serial Device to a telnet port
You can achieve this using ser2net.
The ser2net program comes up normally as a daemon, opens the TCP ports specified in the configuration file, and waits for connections. Once a connection occurs, the program attempts to set up the connection and open the serial port. If another user is already using the connection or serial port, the connection is refused with an error message.
Install ser2net:
file consists of one or more entries with the following format:
after modifying the configuration file you must restart the service
The ser2net program comes up normally as a daemon, opens the TCP ports specified in the configuration file, and waits for connections. Once a connection occurs, the program attempts to set up the connection and open the serial port. If another user is already using the connection or serial port, the connection is refused with an error message.
Install ser2net:
sudo apt-get install ser2netnow configure it
sudo vi /etc/ser2net.confThe configuration file already comes with some examples, you just have to modify them to suit your needs. This
file consists of one or more entries with the following format:
<TCP port>:<state>:<timeout>:<device>:<options>or
BANNER:<banner name>:<banner text>
after modifying the configuration file you must restart the service
/etc/init.d/ser2net restart
Labels:
Linux,
Networking
Possibly Related Posts
Tuesday, 8 May 2012
How to open winmail.dat files on Linux
The winmail.dat file is a container file format used by Microsoft Outlook to send attachments in richtext formatted emails. To open winmail.dat on Linux, use the tnef utility.
Installation
Open a shell window, navigate to the directory where the winmail.dat file is saved, then execute the command:
For more information use
Installation
sudo apt-get install tnefUsage
Open a shell window, navigate to the directory where the winmail.dat file is saved, then execute the command:
tnef --save-body -f winmail.datto extract all files that are stored in the winmail.dat into the current directory.
For more information use
man tnef
Labels:
Command Line,
email,
Linux
Possibly Related Posts
Subscribe to:
Posts (Atom)