Hi Everyone,
I am a bit new at learning this bash syntax. I have a problem at work that needs to be addressed. We find we are spending quite a bit of time killing old processes created by oracle replication that have been restarted later in the week. Because the replication takes time to complete (in days) I want to kill those processes that are 4 days and older.
I found this bit of code that will work just fine but I can’t seem to hook it up to my ps statement and I am at a loss as how to do this.
NOTE: the grep word “hald” is actually one of the linux processes. Something to work with.
There are two variables the first one (print $2) is the pid and the second is the date ($9). The numbers 2 and 9 are the columns numbered left to right. That output looks like this:
I am trying to pass in the date ($9) to the “todate” but am getting confused with the available formatting.
Once I get this to work returning the number of days then I can test it and issue the kill command for the associated pid ($2).
Running the code alone with the dates already there works fine.
The default date format is the following: Tue Oct 2 14:04:31 PDT 2012 . All I want is the day which is represented by date +%d and this returns 02. How can I represent $9 as date +%d ??
Any reference book recommended for reading would be appreciated.
Moderator's Comments:
Please use code tags, avoid odd font settings thanks.
Last edited by jim mcnamara; 10-02-2012 at 06:21 PM..
Thank you for the quick response. All this bash scripting is new to me so I will go over in great detail what was just written to understand this code. I need to get this stuff in my head and the only way to do it for me is just to "do it". I appreciate you being a mentor.
I will let you know how it runs.
regards,
al
---------- Post updated at 07:20 AM ---------- Previous update was at 06:52 AM ----------
Good Morning,
I am reading the code over and I did some research on the portion | grep -v grep|. The formula is grep pattern filename1 filename2.
I can't seem to understand why this is done nor where the -v is coming from.
We have C shell and we are executing the below script:
#!/bin/csh -f
if ($#argv != 2) then
echo "Usage $0 DirecotryPath Inputfilename"
exit 1
endif
set dir=$1
set fname=$2
echo $dir
foreach line ( `cat $fname` )
echo \ ======================================== >>... (2 Replies)
Greetings all,
If I have a SH script that calls a PERL script in the following way:
perl $HOME/scripts/config.properties
And in the config.properties PERL file, this Perl script only sets a number of environmental parameters in the following way:
#!/usr/bin/perl
$VAR1 = (
... (3 Replies)
I want get a number(ID) from a sentence which has been grepped from file using error number.
For Example:
#!/bin/ksh
echo "Enter RRS ID: "
read rrs
echo "Enter error number:"
read err
scp -pr ptc-avdbamdw102:/home/icsprd/M3logs/Accurate/logs/corp_post/$rrs.*.err.txt $HOME/daemon_mail/... (7 Replies)
Hi All....
I need to pass date into awk and parse logfile based on that.... i used both awk and /usr/xpg4/bin/awk... both are throwing up error.....
So here is the stuff...
when i use /usr/xpg4/bin/awk :
DATE=`date '+%Y %b %d'`
START=00
END=23
/usr/xpg4/bin/awk -v DATE={"$DATE"} -v... (3 Replies)
Dear Friends,
I need your help once again.
I have a flat file from which I have grepped something and kept in a separate file for some reason. I want to replace these grepped srtings with the strings in another file.
E.g.
Actual_file.txt
COLOR: 33179 Lakme SEPT2011
Lot No: BR25324
... (5 Replies)
Im trying to pass curl a list of arguments... one of which is a date... When I run from the command line it works fine but when i try to run the same from a script passing variables it reformats the date for some reason and doesn't work. Example:
curlstring=xxxxxxxxxxx.xxx.xxx:8090/csv/... (1 Reply)
Hi,
Anyone can help me on how to solve my problem not getting the actual $DATE saying . Here my scripts;
#!/bin/sh
DATE='20110331'
sftp -oUserKnownHostsFile=/.ssh/known_hosts -oIdentityFile=/.ssh/id_rsa -b /source/transfer.sh server1@sftp.com <<EOF
#tranfer.sh
put... (3 Replies)
I am following the tread number 81556 to grep a file and send the results in email.
#/bin/bash
/bin/grep -i 'invite sip' /var/log/asterisk/full
if echo "found" |
mail -s 'invite sip' mail@gmail.com
When I just build it to grep and mail, it works fine. However, the if statement causes... (4 Replies)
Hi All,
I have a crontab entry for every 5 min running.
5 * * * * /tmp/scripts/ksh/CsVues_H.sh `date +%Y%m%d_%H` >> /tmp/scripts/ksh/Cronresult.log
and I am passing the date parameter. ( `date +%Y%m%d_%H` )
But the parameter values which i am expecting inside the script is... (6 Replies)
Hi
I need to pass a date argument with my shell script. Can any one send me code for the same.
eg For 15th Aug 2006. Iwant to pass parameter like this
./startenv.sh 08/15/2006.
Everyday date argument must change. Will the below code work ?
./startenv.sh date '+%m/%d/%y'
THanks... (1 Reply)