歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
您现在的位置: Linux教程網 >> UnixLinux >  >> Linux基礎 >> 關於Linux

linux expect實現自動登錄腳本

 1)安裝expect

  [root@server ~]# yum install -y expect

  2)編寫腳本

  #!/usr/bin/expect -f

  #created by mis_yw 2013-11-30

  #verify virus by system user oa

  #set password [1index $argv 0 ]

  #set timeout 10.

  set file [ lindex $argv 0 ]

  spawn su -c "/opt/kaspersky/kav4fs/bin/kav4fs-control --scan-file $file" root

  expect {

  "*Password:" {send "XXXXXX\r"}

  }

  interact

  #!/bin/sh

  #created by mis_yw 2013-11-30

  #verify virus.

  file=$1

  if [[ ! -e $file ]] ;then

  #echo "$file is not exsit."

  echo no

  exit 0

  fi

  infected=`./verifyvirus $file | grep Infected | grep 0`

  if(($?)) ;then

  echo yes

  else

  echo no

  fi

Copyright © Linux教程網 All Rights Reserved