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 > /home/oracle/refresh/refresh_ux634.sh.log 2>&1

In crontab -l, there are many jobs, i need to grep job name like 'refresh_ug634.sh' and corresponding log name like 'refresh_ug634.sh.log '.

I am thinking of making a universal script that can grep job name, log name and hostname for one server.

Then, suppose i modify the refresh_ug634.sh script and call that universal script and echo those values when the script gets executed.

Please can anyone help.

All i need to do is have footer in all the scripts running in crontab in one server.
job file name
log file name
hostname

Please suggest if any better solution. Thanks.

I just need to get those three information in every crontab shell script at footer running on that server.

Shell script :- location of the script
Log location :- log file name and location
Sever job ran :- server name

I have to append the disclamer on email for every shell script with above info

Try something this..

To get script path and log file path..

crontab  -l | awk '{for (i=1;i<=NF;i++) { if ($i ~ /^\//)  {print $i }}}'

To get names

crontab  -l | grep -o -i -E '[^/]*\.sh|[^/]*\.log'

Not sure about how we can collect server name..:confused: