shell100例 不会的语句 man bash查询

shell100例 不会的语句 man bash查询
1、每天新建文件
#!/bin/bash
DATE="`date +%F`.log"
DEST=/tmp
cd $DEST
echo "`pwd`"
if [ ! -e $DATE ];then
    touch $DATE;df -hT > $DATE;
fi
date -s "2021-03-25 09:59:58"
tail -f /var/log/cron
crontab -e
*  10  *  *  * bash /date/practice/shell100/touch_file_daily.sh
2、通过位置变量创建 Linux 系统账户及密码
#!/bash/bin
useradd $1
( echo $2 | passwd --stdin $1 ) &> /dev/null
bash -n create_user_passwd.sh
bash create_user_passwd.sh test4 123
3、跨主机免除密码认证
#!/bin/bash
HOSTIP="
10.0.0.201
10.0.0.202
10.0.0.206
"

rpm -q sshpass  &> /dev/null || yum -y install sshpass
[ -f /root/.ssh/id_rsa ] || ssh-keygen -f /root/.ssh/id_rsa -P ''
export SSHPASS="123"
for i in $HOSTIP;do
    sshpass -e ssh-copy-id -o StrictHostKeyChecking=no $i

done
[root@centos8 /date/shell2 ]$ whatis sshpass
sshpass (1)          - noninteractive ssh password provider
-e            Password is passed as env-var "SSHPASS"

[root@centos8 /date/practice ]$ whatis ssh-keygen       
ssh-keygen (1)       - authentication key generation, management and conversion
[-f output_keyfile]
[-P old_passphrase]

[root@centos8 /date/practice ]$ whatis ssh-copy-id 
ssh-copy-id (1)      - use locally available keys to authorise logins on a remote machine
ssh-copy-id [-f] [-n] [-i [identity_file]] [-p port] [-o ssh_option] [user@]hostname

ssh
-o option
Can be used to give options in the format used in the configuration file.  This is useful for specifying options forwhich there is no separate command-line flag.  For full details of the options listed below, and their possible values,see ssh_config(5).

StrictHostKeyChecking
If this flag is set to “no” or “off”, ssh will automati‐cally add new host keys to the user known hosts files and allow connections to hosts with changed hostkeys to proceed,subject to some restrictions
4、30s检测本机的80端口是否开启,未开启的话重启httpd服务,并邮件通知自己
#!/bin/bash
#fielname=chech_80_httpd.sh
netstat -ntl |grep -w 80
if [ $? -eq 1 ];then
systemctl restart httpd && mail -s "`date +%F-%T` httpd restart" ******@qq.com
echo "`date +%F-%T` httpd server abnormal  restart" >> /tmp/httpstatus.log
else
echo "`date +%F-%T` httpd server normal" >> /tmp/httpstatus.log
fi
crontab -e
1/2 *   *  *  * bash /date/shell1/chech_80_httpd.sh
#提示:errors in crontab file, can't install
#无法执行,ctrontab不支持30s

#crontab测试完成记得取消定时任务
#!/bin/bash
#解决crontab不支持30s
#crontab最小为1分钟,所以创建两个执行脚本,一个立即执行,一个脚本在30s之后执行,实现脚本半分钟运行一次
#fielname=chech_80_httpd_30s.sh
sleep 30
. /date/shell1/chech_80_httpd.sh
* * * * * bash /date/shell1/chech_80_httpd.sh;/date/shell1/chech_80_httpd_30s.sh

[root@centos8 /date/shell1 ]$ cat /tmp/httpstatus.log 
2021-03-28-19:56:01 httpd server normal
2021-03-28-19:56:32 httpd server abnormal  restart
2021-03-28-19:57:01 httpd server normal
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值