0
我需要通过邮件发送的文件名,文件的时间戳和它的行数,如果它包含超过1000行。的Linux:sendmail的在bash脚本
的LL -h是不是在我的脚本工作(引发错误和发送的邮件是空白的),虽然它的工作作为一个单独的命令。
不工作:
#!/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 [email protected] #throws error: line 7: ll: command not found
else
echo "In the file $1 there are less than $rows rows"
fi
我执行我的脚本如下:
bash num_rows.sh ~/script/file.log
工作:
ll -h ~/script/file.log | sendmail [email protected]
是什么'型ll'输出?我怀疑'll'只是一个别名,脚本可能不知道你的bash别名。 – mabako
shell别名,这'll'几乎可以肯定是,解决为'LS -l',一般不会在非交互的shell会话中可用,像运行脚本的一个。 – twalberg
非常感谢您的意见!我没有意识到这一点!我在脚本中将别名从'll -h'更改为'ls -lh'并解决了问题! –