[英]How to “export” out put of command “date”? (linux / expect / sftp)
I want to schedule a file copy from sftp server. 我想计划从sftp服务器复制文件。 public key is not allowed so I know only one way to use expect.
公钥是不允许的,所以我只知道一种使用Expect的方法。
Problem is that file name is changing every day, but file name is actually date+.csv so I can schedule it. 问题是文件名每天都在变化,但是文件名实际上是date + .csv,所以我可以安排它。
But unable to set variable file name... 但是无法设置变量文件名...
I want to do something like this in 2 scripts. 我想在2个脚本中执行类似的操作。
file name=Date %Y%m%d 文件名=日期%Y%m%d
connect to sftp server get file name. 连接到sftp服务器获取文件名。
My bast efforts are like as below. 我的努力如下。
my *.sh script = 我的* .sh脚本=
#!/bin/sh
file=$(date --date='-2 days' +%Y%m%d.csv)"
# looking for something like this (20121031.csv)
export file
expect /home/desk4/task/sftp.exp
My expect script located on "/home/desk4/task/sftp.exp" 我的期望脚本位于“ /home/desk4/task/sftp.exp”上
spawn /usr/bin/sftp user@server.com
expect "user@server.com's password:"
send "password"
send "\r"
expect "sftp>"
spawn "get $file \r"
expect "sftp>"
send "bye \r"
Error 错误
./sftp.sh: 3: export: 20121031.csv: bad variable name ./sftp.sh:3:导出:20121031.csv:错误的变量名
#!/bin/sh
file=$(date)
export $file
expect /home/harshit/Desktop/1/sftp.exp
======================================= Error = ./sftp.sh: 3: export: 2: bad variable name ========================================= // sftp.sh:3:导出:2:错误的变量名
--end-- - 结束 -
Thanks for your replay.. 感谢您的重播。
The "bad variable name" error is due to you exporting the value of the variable, not the name of the variable: export $file
is wrong, use export file
“错误的变量名称”错误是由于您导出变量的值而不是变量的名称而引起的:
export $file
错误,请使用export file
In expect, you access environment variables through the global env
array, so use $env(file)
not $file
不出所料,您可以通过全局
env
数组访问环境变量,因此请使用$env(file)
而不是$file
Go ahead and issue export and variable in the same line: 继续并在同一行中发布export和variable:
$export filename=`date +'%F' | sed 's/[-]//g'`.csv
$echo $filename
20121103.csv
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.