Script to repeat commands
Hi folks,
I have to run 20+ commands repeatedly whenever turning on a PC as follows; $ su $ password # command 1 # command 2 # command 3 /mnt/directoy-A (popup, if correct then run) # command 4 # command 5 etc. I'm prepard to write a simple script to do the job. Please advise how to start? With Shell or Perl? TIA B.R. satimis |
Use BASH script
Use a shell script, something like:
Code:
#!/bin/bash Code:
# cp myscript.sh /etc/rc.d/init.d/myscript Now, if you need this to run at log in, it'll be a bit different. You'll want to put the script somewhere in the user's home directory and then edit your .bashrc file and add Code:
~/myscript.sh One more thing, you'll have to Code:
# chmod ug+x myscript.sh Hope that helps. Need more info, use Google to find out more info on bash scripting. -- the dUdeMan |
Re: Use BASH script
Hi linuxLuser,
Tks for your detail advice and link. Comment on following script would be appreciated. Code:
#!/bin/bash 2) Commencing from command-4 onwards, if there is an output, then confirmation is required. Please advise how to add such confirmation to each commands. TIA B.R. satimis |
Re: Re: Use BASH script
Hi linuxLuser,
Tks for your detail advice and link. Comment on following script would be appreciated. Code:
#!/bin/bash 2) Commencing from command-4 onwards, if there is an output, then confirmation is required. Please advise how to add such confirmation to each commands. TIA B.R. satimis |
Code:
#!/bin/bash Code:
if [ $OUTPUT ="/mnt/lfs" ]; then |
Hi shanenin,
Tks for your advice. <snip> 1) Only command-3 should have output = /mnt/lfs. All commands should have no output. If there is any I need to confirm the output before continue to next command 2) All commands don't carry number. It is only for easy reference/understanding I marked the command with a number 3) All Code:
OUTPUT=$(command-x) Hereunder is the script. Please comment. TIA Code:
#!/bin/bash B.R. satimis |
I don't even know if this'll work and I can't test it out at the moment. But I think it should. I can only think of doing this with nested if-statements. If this were C/C++, I'd probably use something to the effect of function pointers. But I don't know. This bit o' script doesn't seem all that long to me, actually.
Code:
#!/bin/bash I hope that's what you're looking fer. -- the dudemaN daVE |
One thing I found out was that the if [ "yes" = $(command-1) ]; then should instead read if [ "yes" = "$(command-1)" ]; then (quotes around the $(command-1) part).
I was able to make some tests with this. I made my own script that calls several other scripts, and it has the same format as what I put above and it works well. I really don't see another shorter way. -- the dUDeman DavE |
Hi linuxLuser,
Tks for your advice. Quote:
Whether 1) You meant "myscript" being Code:
command-1 Code:
command-1 Code:
full_command_line ; Code:
cmd1="full_command_line" Please advise. TIA B.R. satimis |
All times are GMT -5. The time now is 07:46 PM. |