Contoh Soal Shell Script

Soal :
Buatlah sebuah shell script yang menggunakan dialogbox yang terdiri login form berisi inputan username dan password, ketika berhasil login akan menampilkan pesan gagal atau berhasil login
Jawab :
#!/bin/bash

dialog –title “Menu Pilihan” –inputbox “1. Registrasi User\n2. Login” 0 0 2>MenuPilihan

MenuPilihan=`cat MenuPilihan`
rm MenuPilihan

case $MenuPilihan in
1 ) dialog –title “Registrasi User” –inputbox “Masukkan Nama User yang hedak dipakai” 0 50 2>User
UserName=`cat User`
rm User
dialog –title “Registrasi User” –passwordbox “Masukkan Password untuk User[$UserName]” 0 50 2>Pass
Password1=`cat Pass`
dialog –title “Konfirmasi Password” –passwordbox “Ulangi password anda sebelumnya” 0 50 2>Pass
Password2=`cat Pass`
rm Passsleep 2
if [ $Password1 == $Password2 ];then
dialog –msgbox “User Berhasil dibuat !!!” 5 50
cd DataBase
echo $Password1 >$UserName
cd ..
else
dialog –msgbox “Anda Salah Memasukkan Password !!!” 5 50
fi
;;
2 ) dialog –title “Login” –inputbox “Masukkan Nama User !!!” 0 50 2>User
UserName=`cat User`
rm User
CanLogin=”FALSE”
for RegisteredUser in $(ls DataBase)
do
if [ $RegisteredUser == $UserName ];then
CanLogin=”TRUE”
fi
done
sleep 2
case $CanLogin in
“TRUE” ) dialog –title “Login” –passwordbox “Masukkan Password” 0 50 2> Pass
Password=`cat Pass`
rm Pass
UserPass=`cat DataBase/$UserName`
if [ $Password == $UserPass ]; then
dialog –msgbox “Login Berhasil !!!!!!!!!!!!!!!” 5 50
else
dialog –msgbox “Salah Password !!!!!!!!!!!!!!!!” 5 50
fi
;;
“FALSE” ) dialog –msgbox “User[$UserName] belum terdaftar silakan regitrasi terlebih dahulu !!!!” 5 50
;;
esac
;;
* ) echo “Salah Inputan”
;;
esac

If you enjoyed this post, please consider to leave a comment or subscribe to the feed and get future articles delivered to your feed reader.

Comments

No comments yet.

Leave a comment

(required)

(required)