首页 技术 正文
技术 2022年11月9日
0 收藏 711 点赞 4,549 浏览 2110 个字

设计一个shell程序,添加一个新组为class1,然后添加属于这个组的30个用户,用户名的形式为stdxx,其中xx从01到30。

i=1
groupadd class1
while [ $i -le 30 ]
do
if [ $i -le 9 ] ;then
USERNAME=stu0${i}
else
USERNAME=stu${i}
fi
useradd $USERNAME
chgrp -R class1 /home/$USERNAME
i=$(($i+1))
done

编写shell程序,实现自动删除50个账号的功能。账号名为stud1至stud50。

#!/bin/sh
i=1
while [ $i -le 50 ]
do
userdel -r stud${i}
i=$(($i+1 ))
done

mysql备份实例,自动备份mysql,并删除30天前的备份文件

#!/bin/sh#auto backup mysql
#wugk 2012-07-14
#PATH DEFINEBAKDIR=/data/backup/mysql/`date +%Y-%m-%d`
MYSQLDB=www
MYSQLPW=backup
MYSQLUSR=backupif[ $UID -ne 0 ];then
echo This script must use administrator or root user ,please exit!
sleep 2
exit 0
fiif[ ! -d $BAKDIR ];then
mkdir -p $BAKDIR
else
echo This is $BAKDIR exists ,please exit ….
sleep 2
exit
fi###mysqldump backup mysql/usr/bin/mysqldump -u$MYSQLUSR -p$MYSQLPW -d $MYSQLDB >/data/backup/mysql/`date +%Y-%m-%d`/www_db.sqlcd $BAKDIR ; tar -czf www_mysql_db.tar.gz *.sqlcd $BAKDIR ;find . -name “*.sql” |xargs rm -rf[ $? -eq 0 ]&&echo “This `date +%Y-%m-%d` RESIN BACKUP is SUCCESS”cd /data/backup/mysql/ ;find . -mtime +30 |xargs rm -rf

自动安装Nginx脚本,采用case方式,选择方式,也可以根据实际需求改成自己想要的脚本

#!/bin/sh###nginx install shell
###wugk 2012-07-14
###PATH DEFINESOFT_PATH=/data/soft/
NGINX_FILE=nginx-1.2.0.tar.gz
DOWN_PATH=http://nginx.org/download/if[ $UID -ne 0 ];then
echo This script must use administrator or root user ,please exit!
sleep 2
exit 0
fiif[ ! -d $SOFT_PATH ];then
mkdir -p $SOFT_PATH
fidownload ()
{
cd $SOFT_PATH ;wget $DOWN_PATH/$NGINX_FILE
}install ()
{
yum install pcre-devel -y
cd $SOFT_PATH ;tar xzf $NGINX_FILE ;cd nginx-1.2.0/ &&./configure –prefix=/usr/local/nginx/ –with-http_stub_status_module –with-http_ssl_module
[ $? -eq 0 ]&&make &&make install
}start ()
{
lsof -i :80[ $? -ne 0 ]&&/usr/local/nginx/sbin/nginx
}stop ()
{
ps -ef |grep nginx |grep -v grep |awk ‘{print $2}’|xargs kill -9
}exit ()
{
echo $? ;exit
}###case menu #####case $1 in
download )
download
;;install )
install
;;start )
start
;;
stop )
stop
;;* )echo “USAGE:$0 {download or install or start or stop}”
exit
esac

文件上传,列出部分代码

#!/bin/shDATE=`date +%Y_%m_%d_%H`if [ $1 ]
then
for file in $(sed '/^$/d' $1) //去掉空行
do
if [ -f $file ] //普通文件
then
res=`scp $file $2:$file` //上传文件
if [ -z $res ] //上传成功
then
echo $file >> ${DATE}_upload.log //上传成功的日志
fi
elif [ -d $file ] //目录
then
res=`scp -r $file $2:$file`
if [ -z $res ]
then
echo $file >> ${DATE}_upload.log
fi
fi
done
else
echo "no file" >> ${DATE}_error.log
fi
相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,489
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,904
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,737
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,490
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:8,128
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:5,290