Solaris shell 脚本

发布于 2025-01-02 08:21:28 字数 649 浏览 0 评论 0原文

我正在编写一个脚本来使用一些规则来 ftp 一些文件。但我在创建 ftp 会话脚本时遇到问题。

下面是我现在正在使用的 shell 脚本。

#!/bin/bash
cd /var/ericsson/nin/charging/archive
date=`(/usr/bin/perl -e '($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst)=localtime(time()-24*60*60);printf "%4d%02d%02d", $year+1900,$mon+1,$mday;')`
movedFile=`ls | grep $date`
HOST=xxxx
USER=xxxx
PASSWD=xxxxx
for i in $movedFile; 
do
    echo $date >> trial.txt
    echo "Uploading file $i" >> trial.txt
    ftp -n $HOST
    quote USER $USER
    quote PASS $PASSWD
    binary
    cd TEMP
    put $i
    quit
    END_SCRIPT
    echo "kk" 
done

问题是。无法触发ftp的引用命令。

I am writing a script to ftp some files using some rules. But I have problems with the scripts ftp session creation.

below is the shell script I am using right now.

#!/bin/bash
cd /var/ericsson/nin/charging/archive
date=`(/usr/bin/perl -e '($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst)=localtime(time()-24*60*60);printf "%4d%02d%02d", $year+1900,$mon+1,$mday;')`
movedFile=`ls | grep $date`
HOST=xxxx
USER=xxxx
PASSWD=xxxxx
for i in $movedFile; 
do
    echo $date >> trial.txt
    echo "Uploading file $i" >> trial.txt
    ftp -n $HOST
    quote USER $USER
    quote PASS $PASSWD
    binary
    cd TEMP
    put $i
    quit
    END_SCRIPT
    echo "kk" 
done

the problem is. It is unable to trigger quote commands of ftp.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

把时间冻结 2025-01-09 08:21:28

查看bash 此处文档。您正在寻找的语法是:

  ftp -n $HOST <<END_SCRIPT
  quote USER $USER
  quote PASS $PASSWD
  binary
  cd TEMP
  put $i
  quit
END_SCRIPT

Check out bash Here Documents. The syntax you're looking for is:

  ftp -n $HOST <<END_SCRIPT
  quote USER $USER
  quote PASS $PASSWD
  binary
  cd TEMP
  put $i
  quit
END_SCRIPT
阳光的暖冬 2025-01-09 08:21:28

因为评论里看不到。这是正确的答案适用于我的情况

cd xxxx 
date=(/usr/bin/perl -e '($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst)=localtime(time()-24*60*60‌​);printf "%4d%02d%02d", $year+1900,$mon+1,$mday;') 
movedFile=ls | grep $date 
HOST=xxxx 
USER=xxxx 
PASSWD=xxxx 
for i in $movedFile; 
do 
   echo $date >> xxxx.log 
   echo $i >> xxxx.log 
   ftp -n $HOST <<End-Of-Session user "$USER" "$PASSWD" 
   binary 
   cd TEMP 
   put $i 
   quit 
   End-Of-Session 
done

since it is unable to be seen in the comments. here is the correct answer worked my situation

cd xxxx 
date=(/usr/bin/perl -e '($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst)=localtime(time()-24*60*60‌​);printf "%4d%02d%02d", $year+1900,$mon+1,$mday;') 
movedFile=ls | grep $date 
HOST=xxxx 
USER=xxxx 
PASSWD=xxxx 
for i in $movedFile; 
do 
   echo $date >> xxxx.log 
   echo $i >> xxxx.log 
   ftp -n $HOST <<End-Of-Session user "$USER" "$PASSWD" 
   binary 
   cd TEMP 
   put $i 
   quit 
   End-Of-Session 
done
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文