期望与cron不是手动

时间:2015-09-02 09:51:33

标签: ssh cron spawn

backup.sh有:

#!/bin/bash
expect backup.exp
tr -d '\15\32' < backup.templog  >  backup.log

backup.exp有下一个内容:

#!/usr/bin/expect -f
puts "----------------- [exec date +%Y.%m.%d\ %H:%M:%S] ------ exp start -----\n"
spawn ssh root@someIP2
expect "# "
    send "su - postgres\r"
expect "\$ "
    send "ls -lh db.dump.gz\r"
send exit\r
send exit\r
interact

当我像下一个手动运行时那样:

bash backup.sh  >>  backup.templog  2>&1

我接下来,我喜欢:

spawn ssh root@someIP
Linux db01 3.2.0-4-amd64 #1 SMP Debian 3.2.68-1+deb7u1 x86_64

The programs included with the Debian GNU/Linux system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.

Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent
permitted by applicable law.
Last login: Wed Sep  2 11:06:02 2015 from someIP2
root@db01:~# su - postgres
postgres@db01:~$ ls -lh /var/lib/postgresql/db.dump.gz
-rw-r--r-- 1 postgres postgres 218M Sep  2 10:39 /var/lib/postgresql/db.dump.gz
postgres@db01:~$ exit
logout
root@db01:~# exit
logout
Connection to someIP2 closed.

但是有了cron(有一条线):

*  *   *  *  *  bash backup.sh  >>  backup.templog  2>&1

我只接下来:

spawn ssh root@someIP2
Linux db01 3.2.0-4-amd64 #1 SMP Debian 3.2.68-1+deb7u1 x86_64

The programs included with the Debian GNU/Linux system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.

Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent
permitted by applicable law.
Last login: Wed Sep  2 11:04:13 2015 from someIP1
root@db01:~# su - postgres
postgres@db01:~$

我可以使用cron手动获取相同内容吗?

0 个答案:

没有答案