The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



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

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 10-02-2007
JayC89 JayC89 is offline
Registered User
  
 

Join Date: Oct 2007
Posts: 50
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
  #2 (permalink)  
Old 10-02-2007
porter porter is offline Forum Advisor  
Registered User
  
 

Join Date: Jan 2007
Posts: 2,965
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
this will run the scripts and exit if there is an error returned.
  #3 (permalink)  
Old 10-02-2007
JayC89 JayC89 is offline
Registered User
  
 

Join Date: Oct 2007
Posts: 50
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!
  #4 (permalink)  
Old 10-02-2007
porter porter is offline Forum Advisor  
Registered User
  
 

Join Date: Jan 2007
Posts: 2,965
"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
  #5 (permalink)  
Old 10-02-2007
JayC89 JayC89 is offline
Registered User
  
 

Join Date: Oct 2007
Posts: 50
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
Do the .sh scripts not need to be told to "./"?

Thanks porter!

Jamie
  #6 (permalink)  
Old 10-02-2007
porter porter is offline Forum Advisor  
Registered User
  
 

Join Date: Jan 2007
Posts: 2,965
Quote:
Originally Posted by JayC89 View Post
Do the .sh scripts not need to be told to "./"?
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.
  #7 (permalink)  
Old 10-02-2007
JayC89 JayC89 is offline
Registered User
  
 

Join Date: Oct 2007
Posts: 50
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
Where I currently work we generally go to the directory the .sh script is located and simply;
Code:
./script.sh
Sponsored Links
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 06:07 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0