Operating System - HP-UX
1833476 Members
3084 Online
110052 Solutions
New Discussion

unix command inside expect

 
SAM_24
Frequent Advisor

unix command inside expect

Hi,

How to run unix command and store the output in a variable?

set file1 `/tmp/data +%m%d%y`

above syntax not working. Any help would be appreciated.

Thanks.
Never quit
5 REPLIES 5
David Burgess
Esteemed Contributor

Re: unix command inside expect

Hi,

I assume you are trying to store the date in a variable. Try this :-

# set file1=`date +%m%d%y`
# echo $file1

Regards,

Dave.
Mark Grant
Honored Contributor

Re: unix command inside expect

result=$(command)

However, in your case I think you want

file1="/tmp/data"$(date +%m%d%y)
Never preceed any demonstration with anything more predictive than "watch this"
David Burgess
Esteemed Contributor

Re: unix command inside expect

Mark,

Is he using csh?

So would it be something like :-

set file1="/tmp/data"`date +%m%d%y`

Regards,

Dave.
SAM_24
Frequent Advisor

Re: unix command inside expect

Guys,

My question was unix command inside expect script not in shell script.Your suggestion didn't work.

Thanks.
Never quit
Geoff Wild
Honored Contributor

Re: unix command inside expect

What do you want to do with the variable?

Use it after the expect script ends - or during?

It might be easier to run your unix command and output redirect to a logfile?

Usually in expect - it is command, then response....

IE:

# remove all of the files after mgetting them
send_user "Removing Remote Files:\n"
expect "sftp>"
send -- "rm *\r"
expect "sftp>"

send -- "\r\n"
expect "sftp>"
send -- "quit\r"

# close the log file
log_file
expect eof


Rgds...Geoff
Proverbs 3:5,6 Trust in the Lord with all your heart and lean not on your own understanding; in all your ways acknowledge him, and he will make all your paths straight.