LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (http://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Runs Multiple shell script inside a main script using crontab (http://www.linuxquestions.org/questions/linux-newbie-8/runs-multiple-shell-script-inside-a-main-script-using-crontab-763654/)

srimal 10-22-2009 03:59 AM

Runs Multiple shell script inside a main script using crontab
 
hi all,

I wrote a simple shell script called main.sh and inside it calling another shell script called rename.sh.Both are placed in a same directory.[/home/srimal/test]

$cat main.sh
Code:

#!/bin/sh
echo "Hello Buddy !!!!|Last Update : "`date --date="-1 days" +%Y-%m-%d`"|" >> Report.txt
sh rename.sh
exit

$cat rename.sh
Code:

#!/bin/sh
mv Report.txt "`date --date="-1 days" +%Y%m%d`""Report".txt
exit


What I want to do here is to Run main.sh in every day at 13.10pm
So I did as follows but file rename thing did not execute and it created in my home directory not in the test directory.

$crontab -u srimal -l
Code:

10 13 * * * /home/srimal/test/main.sh
However my idea is to learn how to run multiple shell scripts using crontab rather than only one shell script.Can any one guide me to a solution please.

Thanks.

lutusp 10-22-2009 04:09 AM

Quote:

Originally Posted by srimal (Post 3728244)
hi all,

I wrote a simple shell script called main.sh and inside it calling another shell script called rename.sh.Both are placed in a same directory.[/home/srimal/test]

$cat main.sh
Code:

#!/bin/sh
echo "Hello Buddy !!!!|Last Update : "`date --date="-1 days" +%Y-%m-%d`"|" >> Report.txt
sh rename.sh
exit

$cat rename.sh
Code:

#!/bin/sh
mv Report.txt "`date --date="-1 days" +%Y%m%d`""Report".txt
exit


What I want to do here is to Run main.sh in every day at 13.10pm
So I did as follows but file rename thing did not execute and it created in my home directory not in the test directory.

$crontab -u srimal -l
Code:

10 13 * * * /home/srimal/test/main.sh
However my idea is to learn how to run multiple shell scripts using crontab rather than only one shell script.Can any one guide me to a solution please.

Thanks.

You don't say in any detail what you expected, what you got, or how they differ. In scripts launched from cron, you must use full paths for everything -- executables, paths to files, everything. If you put a fill path before every command and every file reference, including the original cron call, you will get more reliable results.

In your "main.sh" script, you aren't really executing a different script as a separate process, because the original script must wait for the child to exit. Is this what you wanted?

vijay_babu1981 10-22-2009 04:13 AM

First, I would suggest you to use full path of commands when using cron even in your scripts.
Second Cron runs in your home directory, so once again full paths will help.

eg:
Quote:

#!/bin/sh
/usr/bin/echo "Hello Buddy !!!!|Last Update : "`date --date="-1 days" +%Y-%m-%d`"|" >> Report.txt
/usr/bin/sh /home/srimal/test/rename.sh
exit
Note find out the right place of these commands first (they may not always be in /usr/bin)

catkin 10-22-2009 05:36 AM

Quote:

Originally Posted by vijay_babu1981 (Post 3728256)
First, I would suggest you to use full path of commands when using cron even in your scripts.

Good advice. Small clarification: echo is a shell built-in so that does not need a full path (unless you don't want to use the shell built-in). The type command will confirm this
Code:

type echo

chrism01 10-22-2009 06:19 PM

All good advice; I also recommend
Code:

10 13 * * * /home/srimal/test/main.sh >/home/srimal/test/main.log 2>&1
Reading that log file would have pointed out some of your issues.
For really recalcitrant progs, add

set -xv

as the first line after the

#!/bin/bash

line


All times are GMT -5. The time now is 03:03 PM.