Linux:在 bash 脚本中发送邮件
Linux: sendmail in a bash script
如果文件超过 1000 行,我需要通过邮件发送文件名、文件时间戳及其行数。
ll -h 在我的脚本中不起作用(抛出错误并且发送的邮件为空白),尽管它作为一个单独的命令运行。
不工作:
#!/bin/sh
pfad="/home/bspftp/script"
rows=1000
actualsize=$(wc -l <"")
if [ $actualsize -ge $rows ]; then
echo "In the file there are more than $rows rows"
ll -h $pfad/ | sendmail my@mail.net #throws error: line 7: ll: command not found
else
echo "In the file there are less than $rows rows"
fi
我执行我的脚本如下:
bash num_rows.sh ~/script/file.log
工作:
ll -h ~/script/file.log | sendmail my@mail.net
您必须使用 ll
的完整路径或将其添加到您的环境 PATH
变量中。
您可以使用 whereis ll
。
如果文件超过 1000 行,我需要通过邮件发送文件名、文件时间戳及其行数。
ll -h 在我的脚本中不起作用(抛出错误并且发送的邮件为空白),尽管它作为一个单独的命令运行。
不工作:
#!/bin/sh
pfad="/home/bspftp/script"
rows=1000
actualsize=$(wc -l <"")
if [ $actualsize -ge $rows ]; then
echo "In the file there are more than $rows rows"
ll -h $pfad/ | sendmail my@mail.net #throws error: line 7: ll: command not found
else
echo "In the file there are less than $rows rows"
fi
我执行我的脚本如下:
bash num_rows.sh ~/script/file.log
工作:
ll -h ~/script/file.log | sendmail my@mail.net
您必须使用 ll
的完整路径或将其添加到您的环境 PATH
变量中。
您可以使用 whereis ll
。