简体   繁体   中英

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.

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.

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.

You can where it is with whereis ll .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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