LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   How to pass value from a shell script run across ssh back to the parent script? (https://www.linuxquestions.org/questions/linux-newbie-8/how-to-pass-value-from-a-shell-script-run-across-ssh-back-to-the-parent-script-4175605569/)

holpot 05-09-2017 01:26 PM

How to pass value from a shell script run across ssh back to the parent script?
 
Hi, this is the first time I've posted a question. I can usually find the solution with some digging but this time I'm stumped.

I have a script that ssh's to a remote machine and gzips a file. I cant predict the name of the gzipped file as it included the known filesize so I need to pass that name back to the parent script so it knows what to scp.

The parent script on my local machine includes this line:

ssh user@remote bash -s < CREATEFILE.sh $1

Where CREATEFILE.sh does
filesize=$(stat -c %s /path/to/data/$1)
tar -zcvf $1_$filesize.gz /path/to/data/$1
newfile=`ls $1*gz`

then back in the local parent script I would like to be able to do

scp user@remote:/home/$newfile .

but I cant work out how to get the pass the filename back.
(For security reasons I'm not allowed to push/scp the file from the remote location to the local one - it has to be pulled).

I dont know if it matter but I am running in tcsh.

Many thanks.

holpot 05-09-2017 02:51 PM

I got it to work by putting the ssh in back-ticks
name=`ssh user@remote bash -s < CREATEFILE.sh $1`

and everything I had echo-ed in CREATEFILE.sh was returned as $name.

wpeckham 05-09-2017 02:55 PM

If you have solved your problem, could you mark this thread "solved" so that others may find your solution?
Thank you.


All times are GMT -5. The time now is 12:13 AM.