Grep script name with path from crontab


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Grep script name with path from crontab
# 1  
Old 11-18-2014
Grep script name with path from crontab

I need help to grep file name with path from crontab
Code:
ex : 0 5 * * * /tmp/test.sh 2>/tmp/test.log

output : /tmp/test.sh



Moderator's Comments:
Mod Comment Please use code tags next time for your code and data. Thanks

Last edited by vbe; 11-18-2014 at 01:00 PM..
# 2  
Old 11-18-2014
Hi,

Quick & dirty;

Code:
crontab -l | awk '{ print $6 }'

Regards

Dave
# 3  
Old 11-18-2014
Code:
05,10,15.20,25,30 * *  * /tmp/test.sh 2>/tmp/test.log

does not work for above one

Last edited by vbe; 11-18-2014 at 01:01 PM.. Reason: code tags
# 4  
Old 11-18-2014
Because that line you gave is faulty... 05 is not the same as 0 5 ( 2 fields...)
The line you gave is missing the hour 05 belonging to the minutes...

in post#1 the line is correct...
# 5  
Old 11-18-2014
I am looking something like this start with first "/" and end with "2>"

Thanks

Johnny
# 6  
Old 11-18-2014
Code:
n12:/home/vbe/wks $ crontab -l|tail -1
# 05,10,15.20,25,30 * *  * /tmp/test.sh 2>/tmp/test.log
n12:/home/vbe/wks $ crontab -l | awk '{ print $6 }'|tail -1
/tmp/test.sh

Quote:
I am looking something like this start with first "/" and end with "2>"
Is that a new request?
if so open a new thread
# 7  
Old 11-19-2014
On a system with a standards conforming sed, the following should do what you requested:
Code:
crontab -l | sed -n 's|^[^/]*\(/[^[:space:]]*\)[[:space:]]*2>.*|\1|p'

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Grep script name with path

would like to grep everything from first occurrence of / until >(not includes) example : 0 5 * * * /usr/local/bin/shell/test.sh >/tmp/test.log Output would be : /usr/local/bin/shell/test.sh (4 Replies)
Discussion started by: jhonnyrip
4 Replies

2. Red Hat

Crontab sourcing PATH?

Hi, Im trying to run script A which requires path /sbin. I have a crontab entry to run script A every 10 minutes. Script A is executed fine by cron, but because script A requires /sbin in its path it fails to run. My situation is script A get overwritten from time to time so I can't modify... (4 Replies)
Discussion started by: wilsonee
4 Replies

3. Shell Programming and Scripting

Reading a crontab 3 * * 1,3,5 /path/of/script.sh

Hi! We are on AIX 6.1 TL6 I am an Admin for a Content Management application that is hosted on an AIX machine and i am supposed to come up with a cronjob that runs every monday at 03:00 am. The current schedule of that cron job is : 3 * * 1,3,5 /path/of/script.sh But i do not know... (5 Replies)
Discussion started by: atechcorp
5 Replies

4. Shell Programming and Scripting

Need a perl script similiar to grep -r 'word' /path/to/dir"

Hi , i am looking for a perl script to grep for a string in all files inside a directory . bash command . grep -r 'word' /path/to/dir Thanks, Nvil (3 Replies)
Discussion started by: nevil
3 Replies

5. Shell Programming and Scripting

Shell Script to grep Job File name and Log File name from crontab -l

Hello, I am new to shell scripting. I need to write a shell script where i can grep the name of file ie. .sh file and log file from crontab -l. #51 18 * * * /home/oracle/refresh/refresh_ug634.sh > /home/oracle/refresh/refresh_ug634.sh.log 2>&1 #40 17 * * * /home/oracle/refresh/refresh_ux634.sh... (1 Reply)
Discussion started by: guptra
1 Replies

6. Shell Programming and Scripting

Script working when run manually but not in crontab showing path not found

i have a script running using variable defined in .profile when i run that script manually its working but when i run the same script through cron its giving path not found I had defined path in .profile (3 Replies)
Discussion started by: raj_saini20
3 Replies

7. Solaris

cannot add PATH to user crontab file

hi All, here is the problem: I'm not able to specify a PATH inside the user crontab file (/var/spool/cron/crontabs). The only syntax it accepts is the usual "* * * * * file" I'm not able to add PATH, or HOME, or MAILTO, or anything else. when I try to save the crontab, I have the error: ... (1 Reply)
Discussion started by: joe_x
1 Replies

8. Shell Programming and Scripting

absolute path for a script ran with relative path

I have a script in which i want to print absolute path of the same script irrespective of path from where i run script. I am using test.sh: echo "pwd : `pwd`" echo "script name: $0" echo "dirname: `dirname $0`" when i run script from /my/test/dir/struct as ../test.sh the output i... (10 Replies)
Discussion started by: rss67
10 Replies

9. UNIX for Dummies Questions & Answers

grep for a last word from a path

Hi , I want to get the last word from a path. Example:: I have path:: /TEMP_REGRESSION/regression/TESTSUITE/TestCases/Test1201/ext_libs/DATA/INTERNAL/pad_ext.lef I want the last word only.ie pad_ext.lef Please let me know how to grep that word. Thanks in advance (6 Replies)
Discussion started by: gujrathinr
6 Replies

10. UNIX for Dummies Questions & Answers

crontab and path

hi All, here the problem: I'm not able to specify a PATH inside the crontab file. The only syntax it accepts is the usual "* * * * * file" I'm not able to add PATH, or HOME, or MAILTO, or anything else. when I try to save the crontab, I have the error: "crontab: error on previous line;... (3 Replies)
Discussion started by: fuliggians
3 Replies
Login or Register to Ask a Question