Shell scripts

#! /bin/bash

shopt -s -o nounset

declare -i p=0
SRC=${1:?'Please input src files name'}
DEST=${2:?'Plesae input dest files name'}

Total=$(stat -c %s $SRC)
touch $DEST

(cp -f $SRC $DEST; sync) &

{
while ((p < 100))
do
    Size=$(stat -c %s $DEST)
    p=Size*100/Total
    echo $p
    sleep 1
done
} | dialog --guage "复制进度" 10 50 0
#!/bin/bash
host="192.168.99.99 21"
id="user"
pw='mima'
basedir="/var/lib/db"
filename="mybackup.`date +%Y%m%d%H%M`.gz"
cd $basedir
/usr/local/mysql/bin/mysqldump --opt -hlocalhost -uroot -ppswd data | gzip -f>/"$basedir"/"$filename"
ftp -n $host>/dev/null 2>/dev/null < <EOF
user $id    $pw
binary
put $filename
bye
EOF
cd $basedir
rm -rf $filename

#!/bin/bash
myday=`date +%F`
mytime=`date +%T --date="-1 hour"`
##PURGE BINARY LOGS BEFORE '2000-02-02 22:22:22';
#echo $myday $mytime
mysql -uroot -p123456 << EOF

PURGE BINARY LOGS BEFORE '${myday} ${mytime}';

#EOF


#!/bin/bash
#Disable sshd dns
sed -i 's/#UseDNS.*/UseDNS no/g' /etc/ssh/sshd_config
sed -i 's/^GSSAPIAuthentication.*/GSSAPIAuthentication no/g' /etc/ssh/sshd_config
sed -i 's/^#GSSAPIAuthentication.*/GSSAPIAuthentication no/' /etc/ssh/sshd_config

#Sudo log
groupadd admin
echo "%admin ALL=(ALL)  NOPASSWD: ALL" >> /etc/sudoers
echo "Defaults        logfile = \"/var/log/sudo\""  >> /etc/sudoers
echo "local2.debug  /var/log/sudo" >> /etc/syslog.conf
 
#Turn off snmpd log
echo "OPTIONS=\"-LS3d -Lf /dev/null -p /var/run/snmpd.pid\"" >> /etc/sysconfig/snmpd.options
 
#Record sftp log
sed -i '/Subsystem/d' /etc/ssh/sshd_config
echo "Subsystem       sftp    /usr/libexec/openssh/sftp-server -l INFO -f AUTH" >> /etc/ssh/sshd_config
echo "auth,authpriv.*                                          /var/log/sftp" >> /etc/syslog.conf
 

#!/bin/bash
yum install -y vsftpd
yum install -y db4*
rm -rf /etc/vsftpd/vsftpd.conf
cat < < 'EOF' >> /etc/vsftpd/vsftpd.conf

listen_port=21
anonymous_enable=NO
local_enable=YES
write_enable=NO
anon_upload_enable=NO
anon_mkdir_write_enable=NO
anon_other_write_enable=NO
chroot_local_user=YES
guest_enable=YES
guest_username=nobody
user_config_dir=/etc/vsftpd/nobody/
ftpd_banner=welcome vsftp!
pam_service_name=vsftpd.vu
#tcp_wrappers=YES
vsftpd_log_file=/var/log/vsftpd.log
listen=YES
dual_log_enable=YES
xferlog_enable=YES
EOF


cat < < 'EOF' >> /etc/pam.d/vsftpd.vu
auth required /lib64/security/pam_userdb.so db=/etc/vsftpd/vsftpd_login
account required /lib64/security/pam_userdb.so db=/etc/vsftpd/vsftpd_login
EOF

mkdir  /etc/vsftpd/nobody

cat < < 'EOF' >> /etc/vsftpd/nobody/ftpadmin
anon_world_readable_only=NO
write_enable=YES
anon_mkdir_write_enable=YES
anon_upload_enable=YES
anon_other_write_enable=YES
anon_umask=022
file_open_mode=0777
local_root=/tmp
EOF

cat < < 'EOF' >> /etc/vsftpd/nobody/upload
anon_world_readable_only=NO
write_enable=YES
anon_mkdir_write_enable=YES
anon_upload_enable=YES
local_root=/tmp/up
EOF

cat < < 'EOF' >> /etc/vsftpd/nobody/download
anon_world_readable_only=NO
local_root=/tmp/down
EOF

echo "ftpadmin"  > /etc/vsftpd/logins.txt
echo "ftpadmin" >> /etc/vsftpd/logins.txt
echo "upload" >> /etc/vsftpd/logins.txt
echo "upload" >> /etc/vsftpd/logins.txt
echo "download" >> /etc/vsftpd/logins.txt
echo "download" >> /etc/vsftpd/logins.txt

echo "db_load -T -t hash -f /etc/vsftpd/logins.txt /etc/vsftpd/vsftpd_login.db" >/etc/vsftpd/cmd

chmod u+x /etc/vsftpd/cmd

sh /etc/vsftpd/cmd

chkconfig  --level 3 vsftpd on
service vsftpd start

if [ "`whoami`" != "root" ] ;then
 
        print "This must be run as root."
        exit -1
fi
if [ "`uname -m`" == "x86_64" ] ; then
 
        wget -c http://xxoo.tv/xxoo2-2-2.x86_64.tar.gz
 
fi
if [ ! -d /usr/local/jpeg ]
     then 
        tar zxvf jpegsrc.v7.tar.gz
        cd jpeg-7
        ./configure --prefix=/usr/local/jpeg
        make 
        make install
        cd ..
        rm -rf jpeg-7
        echo "gpeg install is ok!"
  fi
if [ -e "./soft.tar.gz" ] && [ ! -d "./soft" ]; then
	tar -zxvf soft.tar.gz
fi

One Reply to “Shell scripts”

发表评论

电子邮件地址不会被公开。 必填项已用*标注