Run bash script within a script - Help

 
Thread Tools Search this Thread
Operating Systems Linux Red Hat Run bash script within a script - Help
# 1  
Old 04-28-2015
Run bash script within a script - Help

Hello -

Iam have been trying to run this Query:

Want to run .auto.bash command in the script. Is there a way i can get this done?

Code:
#!/bin/bash _servers="/tmp/servers.txt" _out="/tmp/output.$$" _ssh=/usr/bin/ssh set -x for server in $_servers do $_ssh $s  ./net/ussdp137/opt/EHS/scripts/auto.bash >>$_out done


Last edited by Scrutinizer; 04-28-2015 at 01:34 PM.. Reason: code tags
# 2  
Old 04-28-2015
I see no value in writing that, or most things, as a one-liner. It won't even work on the same line as the hashbang.

You don't define the variable 's' anywhere, either.

You don't read variables from a file that way, either.

You also don't need to open out.txt twelve times to write to it.

I can only guess that you mean to run the code on the remote side of the ssh call. Sure, you can do that. Redirect it into stdin and it will read it on stdin. Run 'exec bash' to get the shell you want running the way you want.

Code:
#!/bin/bash

while read -r S
do
        ssh "$s" exec /bin/bash < ./net/ussdp137/opt/EHS/scripts/auto.bash
done < /tmp/servers.txt > /tmp/out.txt

This User Gave Thanks to Corona688 For This Post:
# 3  
Old 04-28-2015
Hello Corona688 - Thanks for the Quick Reply.

I just ran the script....and iam getting this error:

Code:
./Autosys.sh: line 5: ./net/ussdp137/opt/EHS/scripts/auto.bash: No such file or directory

So i had already mounted this:

Code:
df -h 

ussdp137:/opt/EHS/scripts
                       78G   11G   64G  15% /tmp/mnt

So if this mount doesnt read the script....i can still run this from the /tmp/auto.bash which i copied over from the mount.

Last edited by Scrutinizer; 04-28-2015 at 01:34 PM.. Reason: code tags
# 4  
Old 04-28-2015
./net/ussdp137/opt/EHS/scripts/auto.bash is the path I got from you. That's a path relative to the current folder.

What is the absolute path to the script? Give it that.
# 5  
Old 05-01-2015
I was able to run the query:

Code:
#!/bin/bash
set -x

for host in `cat /tmp/servers.txt`; do
        ssh -t $host "sudo su - -c /net/ServerX/opt/EHS/scripts/auto.bash"
done

what if i want to edit the script and check to see if this CA folder has been unlink or link example:
lrwxrwxrwx 1 root root 12 Oct 19 2011 CA -> /opt/autosys

So the script will remove the unlink CA.

Thanks!
# 6  
Old 05-01-2015
What do you mean "unlink or link"? Missing, or bad link, or what?

[ -d "/path/to/doesthisexist" ] || echo "does not exist"
# 7  
Old 05-01-2015
Sorry - Basically if the CA is linked that run the Upgrade script. If its unlinked then do not run the script.

---------- Post updated at 12:51 PM ---------- Previous update was at 11:07 AM ----------

So something like this is possible in the script?

lrwxrwxrwx 1 root root 12 Oct 19 2011 CA -> /opt/autosys

Basically if the CA is linked that run the Upgrade script. If its unlinked then do not run the script.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Need to run a bash script that logs on as a non-root user and runs script as root

So I have a script that runs as a non-root user, lets say the username is 'xymon' . This script needs to log on to a remote system as a non-root user also and call up a bash script that runs another bash script as root. in short: user xymon on system A needs to run a file as root user and have... (2 Replies)
Discussion started by: damang111
2 Replies

2. Shell Programming and Scripting

Run R Script in Bash Script

Hi there, I'd like to run a R Script within a Bash Script, which is not a problem to me: Example: #!/bin/bash echo Test R --no-save < test.r My Problem is, that I'd like to define a variable within my Bash Script to assign to my R Script: Example: #!/bin/bash echo Test... (3 Replies)
Discussion started by: NBurkhard
3 Replies

3. Shell Programming and Scripting

ssh to run bash script

I want to use ssh to start a bash script that I have uploaded to a webhost. How do I do that from linux? (2 Replies)
Discussion started by: locoroco
2 Replies

4. Shell Programming and Scripting

Run bash script from webhost

If I have a script like this: while true do wget www.***.com >> file sleep 3600 done Is it possible to upload it to a webhost and have it run indefinitely. I have a hostgator account. How do I do this? (1 Reply)
Discussion started by: locoroco
1 Replies

5. Shell Programming and Scripting

Run bash script within a bash script

Hi everybody, Lets say, I have two bash scripts named down.sh and up.sh located in two different folders named ~/home/a/ and ~/home/b/ Now I want to write another bash script, located in ~/home/ which runs these other two scripts, so that I only have to execute this one comprehensive script... (1 Reply)
Discussion started by: NBurkhard
1 Replies

6. Shell Programming and Scripting

Run bash script without terminal

How can I make a bash script that keeps on running after I have closed the terminal? Or a script that runs without having the terminal window open? (1 Reply)
Discussion started by: locoroco
1 Replies

7. Shell Programming and Scripting

How to run bash script from within MySQL

Can someone tell me the syntax to run a shell script from within MySQL? I know there is a way to do it, but I can't remember the syntax. I thought it was something like: mysql> \. /user/myscript; but I get this error: Failed to open file '/user/myscript;', error: 2 Please help!... (4 Replies)
Discussion started by: peterv6
4 Replies

8. Shell Programming and Scripting

Perl script run a bash script

Hi All, I think the processing of this is much more complex, so I will explain the whole process by codes. First,I wrote a expect script named bsim.exp as follows: #! /usr/local/bin/expect set command set name eval spawn $command switch -exact $command { "bash expecttest.sh" { ... (2 Replies)
Discussion started by: Damon sine
2 Replies

9. Shell Programming and Scripting

how to make your bash script run on a machine with csh and bash

hi, i have a script that runs on bash and would like to run it on a machine that has csh and bash. the default setting on that machine is csh. i dont want to change my code to run it with a csh shell. is there any way i can run the script (written in bash) on this machine? in other words is there... (3 Replies)
Discussion started by: npatwardhan
3 Replies

10. UNIX for Dummies Questions & Answers

How to use cygwin to run bash script

Hi, all, I try to run a quite simple bash script mytest.sh in cygwin, it's content is: #!/bin/bash echo "It is my first bash shell" there are three lines in the script. The second line is blank line. When I run it use command: bash c:/mytest.sh, ... (6 Replies)
Discussion started by: Jenny.palmy
6 Replies
Login or Register to Ask a Question