#!/bin/bash
index = 1
for user in `cat /etc/passwd | cut -d ":" -f 1`
# for user in $(cat /etc/passwd | cut -d ":" -f 1)
do
echo "this is $index user : $user"
index=$(($index + 1))
done
根據系統時間計算明年
#!/bin/bash
# 一個小括號是命令替換
echo "This Year is $(date +%Y)"
# 兩個括號是算數運算
echo "Next Year is $(($(date +%Y) + 1))"
#!/bin/bash
# +%j 是獲取本年過了多少天
days=`date +%j`
echo "This year have passed $days days."
echo "This year have passed $(($days / 7)) weeks."
echo "There $((365 - $days)) days before new year."
echo "There $(((365 - $days) / 7)) weeks before new year."
判斷nginx是否運行,如果不在運行則啟動
#!/bin/bash
# nginx進程個數 去除grep的進程 統計結果數
nginx_process_num=`ps -ef | grep nginx | grep -v grep | wc -l`
echo "nginx process num : $nginx_process_num"
if [ "$nginx_process_num" -eq 0 ]; then
echo "start nginx."
systemctl start nginx
fi
# 注意不要腳本文件名不要用nginx單詞