Sponsored Content
Top Forums Shell Programming and Scripting script that reads all the scripts in the directory and run them within that script Post 302324165 by rakeshawasthi on Wednesday 10th of June 2009 06:23:33 AM
Old 06-10-2009
I have modified this script to tackle 3 issue which I could see.
1) same what you mentioned, calling files dynamically
2) handling wrong input
3) if the script is put in a file, lets say prog.sh, this will be listed in the menu and if an option is chosen to select it, the program will go recursive.

I have modified the script a bit, instead of writing a fresh program...

Code:
print_menu()
{
  n=1
  bar======================================
  printf "%s\n" "$bar" " Please Select a Script"  "$bar"

  for item
  do
     if [[ $item != $prog ]]
     then
      printf "%3d: %s\n" "$n" "$item"
      n=$(( $n + 1 ))
     fi
  done

  echo $prog
  printf "%3d: %s\n" "$n" "Quit"

  printf "%s\n Select 1-%d: " "$bar" "$n"
}

prog=$0
while :
do
  print_menu *.sh
  read x
  case $x in
    [1-$(( $n - 1 ))]) sh `ls -1 *.sh | grep -v $prog | head -n $x | tail -1` ;;
       $n) exit  ;;
        *) echo "Wrong Input\n"
  esac
done

I think it should work for the time being...
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Run scripts within a script..

Hi all... I have several scripts of varying types (shell script, expect script, awk script) that I would like to run within 1 script.. They also take a command line argument (which it is getting successfully). The problem is, the parent script is exiting after the first script it calls is... (2 Replies)
Discussion started by: earnstaf
2 Replies

2. Shell Programming and Scripting

Check if script run by a user directly or via other scripts

Hi, i have a script 'a.sh' that should be called only by certain scripts like b.sh, c.sh Inside a.sh, how can i determine 1) if this script was run directly from command prompt (or scheduler) 2) if called via other scripts? Is there an easy way to get parent process name (not just pid),... (2 Replies)
Discussion started by: ysrinu
2 Replies

3. Shell Programming and Scripting

1 script or multiple scripts?? - check files, run jobs

Question for anyone that might be able to help: My objective is to eheck if a file (a source file) exists in a directory. If it does then, I'd like to call an application (Informatica ETL file...not necessary to know) to run a program which extracts data and loads it into multiple targets. ... (6 Replies)
Discussion started by: jnanasakti
6 Replies

4. UNIX for Dummies Questions & Answers

Sh script to run multiple php scripts

I wrote a .sh script to run 5 php scripts. The problem is that it's running 1 then 2 then 3 in that order .... I want it to execute all 5 at ONCE.... nohup php /home/script1/script1.php && nohup php /home/script2/script2.php && nohup php /home/script3/script3.php && nohup php... (1 Reply)
Discussion started by: holyearth
1 Replies

5. Shell Programming and Scripting

Shell script to run all the python scripts from particular directory

I have N number of python scripts which i am receiving from REST web server and i am saving them in /home/mandar/ . Now i want to write a script to run all the python scripts from this directory and monitor them every minute...if any process is dead or hung it should be restarted by this script. ... (0 Replies)
Discussion started by: Mandar Nandale
0 Replies

6. Shell Programming and Scripting

Using a script to define variables and run multiple other scripts in succession.

I'm pretty new to scripting in Korn shell so please forgive me... What I'm trying to do is to create a script that calls multiple other ksh scripts and defines variables for text files. I need it to define my user defined variables (file paths, date & time stamps, etc that are currently in... (1 Reply)
Discussion started by: bluejwxn8
1 Replies

7. UNIX for Dummies Questions & Answers

Trying to make a script to run 3 other scripts in a screen.

Hello, my name is Spurkle. I'm new to linux stuff. Currently I am trying to make a script which will run three other scripts in screen. This is the code: sudo screen -S hubServ /var/servers/hub/hub.sh sudo screen -S facServh /var/servers/factions/factions.sh sudo screen -S bunServ... (5 Replies)
Discussion started by: Spurkle
5 Replies

8. Shell Programming and Scripting

How to run scripts parallely inside shell script?

Hi , I have 4 scripts example script1,script2,script3,script4 . I have to run script1,script2 and script3 parallely since this 3 scripts dont have dependencies . Once script1,script2 and script3 got completed successfully , I have to trigger script4. Can someone help me on this how to... (10 Replies)
Discussion started by: vinothsekark
10 Replies

9. Shell Programming and Scripting

Run 2 shell scripts simultaneously from one script

i Run 2 scripts on all of around 50 nodes every day. 1.Mod_1.sh 2.Mod_2.sh eg.. i run file with specific node no like Mod_1.sh NODE_(node number) Mod_2.sh NODE_(node number) I want to run both file by using single script with unique node number. Eg.. Mod_new.sh NODE_(node... (11 Replies)
Discussion started by: Ganesh Mankar
11 Replies

10. UNIX for Beginners Questions & Answers

A single script to run multiple scripts

Hi , Can someone help! I need a shell script to run multiple scripts by using single shell script, incase any one of the scripts fails, it should get exit and after trouble shooting if we re-execute it, it should start from the failed script. I have a written a scripting till the... (1 Reply)
Discussion started by: anniesurolyn
1 Replies
tryto(1)						      General Commands Manual							  tryto(1)

NAME
tryto - tries to run a command limited by a timeout or number of tries, can be used to run as svlogd(8) processor. SYNOPSIS
tryto [-pPv] [-t sec] [-k ksec] [-n tries] prog DESCRIPTION
prog consist of one or more arguments. tryto runs and watches prog, feeding its standard input to prog's standard input. If prog exits with a return code other then 0, tryto runs prog again after sleeping one second. If the number of retries reaches the maximal number of tries, tryto prints an error message and gives up. If the timeout sec seconds is reached and prog is still running, tryto sends a TERM signal to prog, waits ksec seconds for prog to termi- nate, then sends a KILL signal if prog still is there, and exits as soon as possible. OPTIONS
-t sec timeout. Set the timeout to send TERM to prog to sec seconds. Default is 180. -k ksec kill timeout. Set the timeout to send KILL to prog to ksec seconds. Default is 5. -n tries Set the maximal number of tries to tries. If prog exited with a return code other that 0, tryto tries to rewind standard input to the beginning using lseek(2) before starting prog again. Default is 5. -p processor. Use this option if you run tryto as a svlogd(8) processor (see below). -P process group. Run prog in a new session and process group, and send signals on timeout to prog's process group instead of its pid. -v verbose. Print verbose messages to standard error. PROCESSOR
If tryto sees the -p option, tryto runs as a svlogd(8) or multilog(8) processor, making use of filedescriptors 4 and 5: Before starting prog, tryto moves the filedescriptor 5 to 2, so all error messages from tryto and prog will be saved in svlogd(8)'s state to be processed on the next run of tryto -p. After starting prog, tryto first feeds all data it reads from filedescriptor 4 into prog's standard input, then all data from filedescrip- tor 0. If prog fails by timeout sec seconds or maximal number of tries, tryto prints all data from standard input to standard output, an error message to standard error, and exits with 0. EXIT CODES
If tryto itself fails, it returns 111. If tryto runs as a svlogd(8) processor, tryto returns 0 in all other cases. If prog was run successfully, tryto returns 0. If prog failed by timeout, tryto returns 100. If prog failed by maximal number of tries, tryto returns the last return code from prog. SEE ALSO
socklog(8), uncat(1), svlogd(8), multilog(8), lseek(2) http://smarden.org/socklog/ http://smarden.org/runit/ AUTHOR
Gerrit Pape <pape@smarden.org> tryto(1)
All times are GMT -4. The time now is 02:04 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy