unix环境下常用工作脚本大全

合集下载
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

工作中常用的脚本

Lyman V an原创(mail:flyfan05@)

1,备份脚本:

主要是date的格式化,以及常用的cp拷贝。

#!/usr/bin/sh

bak_date=$(date +%Y%m%d)

echo "==========vanips bak date is $bak_date================"

echo "+++++++++++++++bak vanips is start...+++++++++"

#ll /test2/vanips/bak/;

rm -rf /test2/vanips/bak/vanips.bak.$bak_date

mkdir -p /test2/vanips/bak/vanips.bak.$bak_date

echo "========copy vanips_run is start...============"

mkdir -p /test2/vanips/bak/vanips.bak.$bak_date/vanips_run

echo "========copy vanips_run is ok=================="

cd /test2/vanips/bak/vanips.bak.$bak_date;

touch 这是备份文件

echo "+++++++++++++++bak vanips is end+++++++++"

2,ftp文件传输

ftp -n <

open $IP ##远程主机的ip地址

user $v_username $v_username ##远程主机的用户名和密码

bin ## 以二进制传输

prompt ## 关闭对话框

lcd $v_localpath ##本地目录

cd $v_remotepath ## 远程主机目录

mput $v_resname ## 需要传输的文件名称

bye

VAN

3,远程登陆

主要用expect脚本来实现交互,下面两个脚本分别实现了rlogin 远程登陆和ssh远程登陆#!/home/bin/expect

set v_host [lindex $argv 0]

set v_username [lindex $argv 1]

set v_password [lindex $argv 2]

set v_command1 [lindex $argv 3]

#延时1s执行以下命令

set timeout 1

spawn rlogin $v_host

expect "Password: "

exec sleep 1

send "$v_password"

send "\r"

expect "*$v_username%"

exec sleep 1

send "$v_command1"

send "\r"

set timeout 300

expect "*$v_username%"

#!/test1/release/expect/bin/expect

# useage :ssh_host_exec_command [host_ip] [user] [password] [system_name] [host_index] [command]

set v_hostip [lindex $argv 0]

set v_username [lindex $argv 1]

set v_password [lindex $argv 2]

set v_systemname [lindex $argv 3]

set v_hostindex [lindex $argv 4]

set v_command [lindex $argv 5]

#延时4s执行以下命令

set timeout 4

spawn ssh -l $v_username $v_hostip

expect "*assword:"

exec sleep 1

send "$v_password"

send "\r"

expect "*UserName):"

exec sleep 1

send "$v_systemname"

send "\r"

expect "*Hostname):"

exec sleep 1

send "$v_hostindex"

send "\r"

expect "*$v_systemname%"

exec sleep 1

send "$v_command"

send "\r"

4,用户界面

简单的echo实现打印

user_interface()

{

echo " \n *****************************************"

echo " * 请选择序号或名称: *"

echo " * \t 1: vanbps *"

echo " * \t 2: vancbs *"

echo " * \t 3: ccsuser *"

echo " * \t 4: vanips *"

echo " * \t 5: vanupintf *"

echo " * \t 6: mutil_user *"

echo " * \t 0: exit *"

echo " *****************************************\n"

}

5,用户问答式交互

echo "\n================是否继续?(y/n):\c====================" read ANS

case $ANS in

y|Y|yes|YES|Yes)

do_deploy

;;

*)

echo "取消!!!"

;;

esac

6,数据库操作

用sqlplus实现

# get_obj_detvanl [object_name] : 获取。。。等信息并保存

get_obj_detvanl()

{

v_obj_name=$1;

v_code_list=/test /util/release/test

cd $HOME/release/ ;

rm obj_info.lst ;

相关文档
最新文档