简体   繁体   English

Linux:bash脚本中的sendmail

[英]Linux: sendmail in a bash script

I need to send a filename, a timestamp of the file and its number of rows via mail if it contains over 1000 rows. 如果文件包含1000行以上,我需要通过邮件发送文件名,文件的时间戳及其行数。

The ll -h is not working in my script (an error is thrown and the sent mail is blank), though it is working as a separate command. ll -h在我的脚本中不起作用(抛出错误并且发送的邮件为空白),尽管它作为单独的命令运行。

Not working: 无法运作:

#!/bin/sh
pfad="/home/bspftp/script"
rows=1000
actualsize=$(wc -l <"$1")
if [ $actualsize -ge $rows ]; then
    echo "In the file $1 there are more than $rows rows"
    ll -h $pfad/$1 | sendmail my@mail.net #throws error: line 7: ll: command not found
else
    echo "In the file $1 there are less than $rows rows"
fi

I execute my script as below: 我执行脚本如下:

bash num_rows.sh ~/script/file.log

Working: 工作:

ll -h ~/script/file.log | sendmail my@mail.net

You must use the fullpath to ll or add it to your environment PATH variable. 您必须使用全路径ll或将其添加到您的环境PATH变量中。

You can where it is with whereis ll . 您可以使用whereis ll在哪里。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM