Getting error while using date as a variable in expect

 
Thread Tools Search this Thread
Top Forums UNIX for Beginners Questions & Answers Getting error while using date as a variable in expect
# 8  
Old 08-07-2018
can anyone help me
# 9  
Old 08-07-2018
Can you sftp this from the command line without using expect?
# 10  
Old 08-07-2018
Personally I think you are making the operation more complicated than it needs to be.

Are you able to use an SSH key pair to make the connection? This would get rid of the need to send passwords.

Are you only sending the one file? The script you have shown in previous posts could have been stripped down to show the problems you are experiencing. If it has not, and you are only sending one file, you could use SCP instead of SFTP, provided you can make use of an SSH key pair. Your script could then be something like:

Code:
#!/bin/bash
remuser=xxx
remhost=yyy
remdir=zzz
logfile=$(date -d "1 day ago" +"LOGS_%Y_%m_%d.tar.gz")
if [[ -e ${logfile} ]]
then scp ${logfile} ${remuser}@${remhost}:${remdir}
else echo "Cannot find log file ${logfile}"
fi

Andrew
# 11  
Old 08-08-2018
Hi Andrew,


My current problem is that when I am trying to run my script by scheduling it in cron it did not work.
however when the same script I run manually it works.


this issue I am not able to figure out
# 12  
Old 08-08-2018
Quote:
Originally Posted by scriptor
Hi Andrew,


My current problem is that when I am trying to run my script by scheduling it in cron it did not work.
however when the same script I run manually it works.


this issue I am not able to figure out
Are you running the script manually from the same directory that it will be run by cron?

What happens when the full pathname of the log file is used in the script?

Andrew
# 13  
Old 08-08-2018
Hi Andrew,
yes the path is same when I run manually or when it runs from cron.


below error I get when script run from cron


Code:
# log
+ log
spawn sftp AUT@xx.xx.xx.xx
Connecting to xx.xx.xx.xx...
AUT@xx.xx.xx.xx's password: 
sftp> cd /home 
sftp> put LOGS_2018-08-08.tar.gz
stat LOGS_2018-08-08.tar.gz: No such file or directory


Last edited by scriptor; 08-08-2018 at 07:46 AM.. Reason: typo
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

How to replace a parameter(variable) date value inside a text files daily with current date?

Hello All, we what we call a parameter file (.txt) where my application read dynamic values when the job is triggered, one of such values are below: abc.txt ------------------ line1 line2 line3 $$EDWS_DATE_INSERT=08-27-2019 line4 $$EDWS_PREV_DATE_INSERT=08-26-2019 I am trying to... (1 Reply)
Discussion started by: pradeepp
1 Replies

2. Shell Programming and Scripting

Expect Redirecting o/p to an Variable

I have a password reset expect script which stores all the op to an file. I need to check the whether password is successfully changed by greping out the file and storing the o/p to a variable. But we try to print the variable , its shows only the command instead of its o/p. ... (2 Replies)
Discussion started by: sudharson
2 Replies

3. Shell Programming and Scripting

Convert a date stored in a variable to epoch date

I am not able to pass date stored in a variable as an argument to date command. I get current date value for from_date and to_date #!/usr/bin/ksh set -x for s in server ; do ssh -T $s <<-EOF from_date="12-Jan-2015 12:02:09" to_date="24-Jan-2015 13:02:09" echo \$from_date echo... (7 Replies)
Discussion started by: raj48
7 Replies

4. Shell Programming and Scripting

Python get the expect value from a variable

the value of the variable is yes group=bsp_16 keyword="82599" test_var="-a xxx -b yyy" I want to get output with -a xxx -b yyy (0 Replies)
Discussion started by: yanglei_fage
0 Replies

5. Shell Programming and Scripting

LINUX ---> Add one date to a date variable

Hi All, I am trying to add one day to the busdt variable i am extracting from a file (DynamicParam.env). I am deriving the busdt as below. Is there any function which I can use to derive as below. If busdt=20120910, then the new derived variable value should be 20120911 If... (2 Replies)
Discussion started by: dsfreddie
2 Replies

6. Shell Programming and Scripting

How to pass variable with spaces from shell to expect?

I need call expect script from shell script and pass values some of which could contain space. How to make expect to treat such values as one variable? (1 Reply)
Discussion started by: urello
1 Replies

7. Shell Programming and Scripting

Assigning last line to variable in expect

As part of an expect script, I have to convert a strange user ID to a conventional UNIX ID. To do this, I read the contents of a file and do a little awk magic. Here's that bit of the expect script: send "awk 'NF == 10 && \$NF == strange_user_id {print \$(NF-2)}' file_with_my_info\r" expect... (0 Replies)
Discussion started by: treesloth
0 Replies

8. Shell Programming and Scripting

passing variable to expect

Please tell me how to pass variable "a b c" to expect from the shell script 1/ example of input file # cat in-file var1 var2 a b c var4 2/ # this is my script - how to pass "a b c" as single variable ? cat in-file | while read x do my-expect x done 3/ # expect script - how to... (0 Replies)
Discussion started by: breaktime123
0 Replies

9. Shell Programming and Scripting

Transfer variable to an expect function

Hi There, I try to transfer a variable from the script to a function which use expect, but I don't succed. #!/bin/sh HPPASS1="$2" send_command() { echo "spawn ssh login@10.10.10.10" echo 'set password ' echo 'sleep 1' echo 'expect "*assword:*"'... (5 Replies)
Discussion started by: sylvainkalache
5 Replies

10. Shell Programming and Scripting

How to check date variable according to the current date?

Hi folks, I need to write a script that should activate a process according to the current hour. The process should be activatet only if the hour is between midnight (00:00) and 07:00. How should I create the condition? Thanks in advance, Nir (2 Replies)
Discussion started by: nir_s
2 Replies
Login or Register to Ask a Question