beginer : shell script

January 20, 2009

well, skrg tiba2 butuh harus coding pake shell script, untung ada mas google yang baik hati.
after dibantu sm mas artikel dari bbrp site, ahirnya scriptnya jalan,
intinya mau buat script utk masuk ke mesin lain, trs harus eksekusi bbrp comand, kl sdh jalan, baru di schedule pk crontab..

  1. karena mau telnet, katanay harus pakai aplikasi "expect" –> apt-get install expect
  2. hbs itu buat contoh scriptnya,
    #!/usr/bin/expect
    set myServer x.x.x.x
    set myUsername username
    set myPassword userpassword
    #login
    # buka sesion telnet
    spawn telnet $myServer
    expect "username:"
    # kirim info user login
    send "$myUsername\r"
    expect "password:"
    expect "%"
    send "$myPassword\r"
    expect "%"
    # contoh perintah, pake ping ya yg mudah :D
    send "ping yahoo.com\r"
    expect "%"
    expect "%"
    # Exit ,
    send "exit\r"
    expect eof
  3. habis itu bs disave dan coba di eksekusi, misal di save pake nama test.sh, maka di eksekusi,
    caranya pake ./test.sh
  4. gagal?!
    nah itu dia, tks lagi buat mas google.. stlh nyari2, ternyata ga akan bs dieksekusi sblm di buka permissionnya
    chmod go+rx test.sh
  5. coba eksekusi lagi ./test.sh
  6. gud lack :p

Comments »

Belum ada komentar.

RSS feed for comments on this post.

TINGGALKAN KOMENTAR

Alamat email tidak akan ditampilkan