#!/bin/bash
read -p "please input a filename:" file
if [ ! -e $file ];then
echo "file is not exits"
elif [ ! -r $file -a ! -w $file ];then
echo "$user can't read and write $file"
else
echo "$file can read or write"
fi
執行結果:
[root@centos7 testdata]# chmod +x per.sh
[root@centos7 testdata]# ./per.sh
please input a filename:/etc/shadow
/etc/shadow can read or write
[root@centos7 testdata]# su cwj
[cwj@centos7 testdata]$ ./per.sh
please input a filename:/etc/shadow
cwj can't read and write /etc/shadow
#!/bin/bash
read -p "please input a file:" file
if [ -e $file ];then
if [ -f $file ];then
suffix=`echo "$file" | awk -f. ''`
if [ $suffix == "sh" ];then
chmod a+x $file
echo "$file change mode success"
else
echo "$file is not script file"
fielse
echo "file is not a normal file"
fielse
echo "file is not exits"
fi
執行結果:
[root@centos7 testdata]# ./excute.sh
please input a file:scp1.exp
scp1.exp is not script file
[root@centos7 testdata]# ./excute.sh
please input a file:per.sh
per.sh change mode success
禁止使用者登入:
#!/bin/bash
read -p "please input user name:" name
id $name >/dev/null
if [ $? -eq 0 ];then
userid=`id $name |sed -r 's/.*=([0-9]+).*/\1/'`
if [ $userid -ge 500 ];then
usermod -s /sbin/nologin $name
echo "usermod success"
else
echo "$name is a system user"
fielse
echo "$name is not exits"
fi
執行結果:
please input user name:cwj
usermod success
[root@centos7 testdata]# ./nologin.sh
please input user name:root
root is a system user
[root@centos7 testdata]# getent passwd cwj
cwj:x:1000:1000:cwj:/home/cwj:/sbin/nologin
允許使用者登入:
#!/bin/bash
read -p "please input user name:" name
id $name >/dev/null
if [ $? -eq 0 ];then
userid=`id $name |sed -r 's/.*=([0-9]+).*/\1/'`
if [ $userid -ge 500 ];then
usermod -s /bin/bash $name
echo "usermod success"
else
echo "$name is a system user"
fielse
echo "$name is not exits"
fi
執行結果:
[root@centos7 testdata]# chmod +x login.sh
[root@centos7 testdata]# ./login.sh
please input user name:cwj
usermod success
[root@centos7 testdata]# ./login.sh
please input user name:root
root is a system user
[root@centos7 testdata]# getent passwd cwj
cwj:x:1000:1000:cwj:/home/cwj:/bin/bash
#! /bin/bash
user10="`head -n $2 $1 | tail -n 1|cut -d: -f3`"
user20="`head -n $3 $1 | tail -n 1|cut -d: -f3`"
let sum=$user10+$user20
echo "user id sum is $sum"
top命令
使用iostat,可以非常詳細的檢視到是哪塊硬碟最繁忙,iostate 預設不安裝在系統中,需要使用yum安裝: yum install iostat
編寫backup指令碼
#!/bin/bash
cp /etc/passwd /home/cwj/testdata/passwd.bak`date +%f-%t`
2、編寫計畫任務
0 6-12/3 * 12 * /home/cwj/testdata/backup
Linux計畫任務管理
前提 atd服務必須執行 root wei init.d yum y install at 安裝atd服務 root wei init.d systemctl start atd 開啟atd服務 root wei init.d systemctl status atd 檢視atd開啟狀態 18 00...
Linux 計畫任務管理crontab at
1.crontab 命令 按照預先設定的時間週期 分鐘 小時 天 重複執行使用者指定的命令操作,屬於週期性計畫任務,預設開啟 var spool cron 使用者 檔案 服務指令碼名稱 etc init.d crond 主要設定檔案 全域性配置檔案,位於檔案 etc crontab 系統預設的設定,...
linux計畫任務的管理
2.一次性計畫任務 at 1 了解at rpm qf which at 檢視屬於哪個軟體包 rpm ql at 檢視at程式安裝的所有軟體 etc 配置檔案 bin 或者 usr sbin 命令 etc rc.d init.d 啟動指令碼 usr share doc 幫助和說明文件 var spoo...