LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 05-09-2017, 01:26 PM   #1
holpot
LQ Newbie
 
Registered: Jan 2017
Posts: 4

Rep: Reputation: Disabled
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.
 
Old 05-09-2017, 02:51 PM   #2
holpot
LQ Newbie
 
Registered: Jan 2017
Posts: 4

Original Poster
Rep: Reputation: Disabled
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.

Last edited by holpot; 05-09-2017 at 03:02 PM.
 
1 members found this post helpful.
Old 05-09-2017, 02:55 PM   #3
wpeckham
Senior Member
 
Registered: Apr 2010
Location: Continental USA
Distribution: Debian, Ubuntu, Fedora, RedHat, DSL, Puppy, CentOS, Knoppix, Mint-DE, Sparky, Vsido, tinycore, Q4OS
Posts: 3,859

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


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] shell script issue how to pass the license exceptance as yes through script rohaanembedded Programming 5 07-03-2013 01:46 AM
Shell script for run an shell script on server using ssh bloodstreetboy Linux - Server 5 01-12-2013 03:23 AM
[SOLVED] net snmp pass persist script, can not run a bash script!! Linux Chips Linux - General 4 12-23-2012 01:50 PM
How to pass command line arguments from one shell script to another shell script VijayaRaghavanLakshman Linux - Newbie 5 01-20-2012 09:12 PM
how to pass a variable from a called script back to the calling script steven.c.banks Linux - General 2 05-05-2008 02:00 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 04:08 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration