我正在运行下面的脚本以使用 lftp 从服务器自动下载文件。它可以工作,但在运行时我收到错误消息
trap: SIGINT: bad trap
Run Code Online (Sandbox Code Playgroud)
如果我用 INT 和 TERM 替换 SIGINT 和 SIGTERM 那么它确实有效,但我不知道它是否达到了同样的目的。这是在 Linux Debian 4.9.2-10 上。
#!/bin/sh
login="login"
pass="password"
host="server.server.com"
remote_dir='~/remote/dir'
local_dir="/local/dir"
base_name="$(basename "$0")"
lock_file="/tmp/$base_name.lock"
trap "rm -f $lock_file" SIGINT SIGTERM
if [ -e "$lock_file" ]
then
echo "$base_name is running already."
exit
else
touch "$lock_file"
/usr/bin/lftp -p 22 -u "$login","$pass" sftp://"$host" << EOF
set sftp:auto-confirm yes
set mirror:use-pget-n 5
mirror -c -P5 "$remote_dir" "$local_dir"
quit
EOF
rm -f "$lock_file"
trap - SIGINT SIGTERM
exit
fi
Run Code Online (Sandbox Code Playgroud)