![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| A simple find and replace without using any regex (bash) | srikanths | Shell Programming and Scripting | 2 | 03-18-2008 08:08 AM |
| Simple date and time calulation in BASH | ripat | Tips and Tutorials | 0 | 10-08-2006 06:15 AM |
| Simple bash for loop problem | kingdbag | Shell Programming and Scripting | 4 | 09-15-2006 01:00 AM |
| simple bash script to ftp? | satnamx | Shell Programming and Scripting | 1 | 04-21-2006 11:18 AM |
| Simple Bash Script | xaphalanx | Shell Programming and Scripting | 3 | 12-21-2005 03:54 PM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
||||
|
Simple BASH script?
Hi guys, I'm new to the forum so forgive me if I'm sounding ... daft.
I currently work in a Tech Support role. Every day we have to generate data by running around 10 .sh scripts. I was thinking instead of having to ./filename 10 times is it possible to right a new script that will run these for me on the relevant order? I'm assuming one of you guys could do this in 2 seconds, but would anyone mind pointing me in the right direction? E.g a template of what the script should look like? Obviously I still think myself to be a novice when it comes to UNIX, but anything to make the little jobs easier would be great! Cheers Jamie |
|
||||
|
Put the following in a file call runall.sh then do
chmod +x runall.sh to execute use ./runall.sh Code:
#!/bin/sh
for d in /path...../first-file.sh \
/path..../second-file.sh \
/path..../third-file.sh \
/path..../fourth-file.sh
do
$d
RC=$?
if test "$RC" != "0"
then
exit $RC
fi
done
|
|
||||
|
Thanks porter, appreciated!
What does the +x specify after the chmod, isn't this normally numbers to specify read, write, execute permissions? Such as 660 or similar? Could you have it so if an error occurred it would ask if you wanted to continue? Thanks again! |
|
||||
|
"chmod +x .... " sets the "executeable" flags which tells the operating system this is a runable program.
Yes you could, Code:
if test "$RC" != "0"
then
echo "continue? [y]/n"
read N
case "$N" in
Y* | y* )
;;
* )
exit $RC
;;
esac
fi
|
|
||||
|
So something along the lines of;
Code:
#!/bin/sh
for d in /path...../first-file.sh \
/path..../second-file.sh \
/path..../third-file.sh \
/path..../fourth-file.sh \
if test "$RC" != "0"
then
echo "continue? [y]/n"
read N
case "$N" in
Y* | y* )
;;
* )
exit $RC
;;
esac
fi
done
Thanks porter! Jamie |
|
||||
|
Depends what is on the path, in UNIX (unlike windows) you normally don't execute programs from the current directory.
If the directory name is not in the command name then the operating system will look for programs in directories listed in the PATH variable. The "./" basically tells the OS what directory "runall.sh" is in. Similarly you should replace the "/path...." to what ever directory your scripts are in. |
|
||||
|
If I had 4 scripts in;
/usr/local/production/temp/ And another 4 in; /usr/local/production/temp/newfolder I could use; Code:
#!/bin/sh
for d in /usr/local/production/temp/first-file.sh \
/usr/local/production/temp/second-file.sh \
/usr/local/production/temp/third-file.sh \
/usr/local/production/temp/fourth-file.sh \
/usr/local/production/temp/newfolder/first-file.sh \
/usr/local/production/temp/newfolder/second-file.sh \
/usr/local/production/temp/newfolder/third-file.sh \
/usr/local/production/temp/newfolder/fourth-file.sh \
if test "$RC" != "0"
then
echo "continue? [y]/n"
read N
case "$N" in
Y* | y* )
;;
* )
exit $RC
;;
esac
fi
done
Code:
./script.sh |
| Sponsored Links | ||
|
|
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|