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?

#!/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

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.

#!/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
1 Like

Hello Corona688 - Thanks for the Quick Reply.

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

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

So i had already mounted this:

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.

./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.

I was able to run the query:

#!/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!

What do you mean "unlink or link"? Missing, or bad link, or what?

[ -d "/path/to/doesthisexist" ] || echo "does not exist"

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.

If stat (or equivalent) is available, you could test the result of e.g.

stat -c%F CA
symbolic link
2 Likes

Thanks RudiC!