#!/bin/bash
# clear the screen
tput clear
# Move cursor to screen location X,Y (top left is 0,0)
tput cup 3 15
# Set a foreground colour using ANSI escape
tput setaf 3
echo “XYX Corp LTD.”
tput sgr0
tput cup 5 17
# Set reverse video mode
tput rev
echo “M A I N – M E N U”
tput sgr0
tput cup 7 15
echo “1. User Management”
tput cup 8 15
echo “2. Service Management”
tput cup 9 15
echo “3. Process Management”
tput cup 10 15
echo “4. Backup”
# Set bold mode
tput bold
tput cup 12 15
read -p “Enter your choice [1-4] ” choice
tput clear
tput sgr0
tput rc
>#!/bin/bash
dialog –title “Delete file” \
–backtitle “Linux Shell Script Tutorial Example” \
–yesno “Are you sure you want to permanently delete \”/tmp/foo.txt\”?” 7 60
# Get exit status
# 0 means user hit [yes] button.
# 1 means user hit [no] button.
# 255 means user hit [Esc] key.
response=$?
case $response in
0) echo “File deleted.”;;
1) echo “File not deleted.”;;
255) echo “[ESC] key pressed.”;;
esac
# find out if TCP port 25 open or not
(echo >/dev/tcp/localhost/25) &>/dev/null && echo “TCP port 25 open” || echo “TCP port 25 close”
你可以 使用循环来查找开着的端口:
PHP代码
12345
echo “Scanning TCP ports…”
for p in {1..1023}
do
(echo >/dev/tcp/localhost/$p) >/dev/null 2>&1 && echo “$p open”
done
输出:
12345678910111213
Scanning TCP ports…
22 open
53 open
80 open
139 open
445 open
631 open
下面的这个例子让你的脚本扮演HTTP客户端:
PHP代码
1234567891011121314
#!/bin/bash
exec 3<> /dev/tcp/${1:-www.cyberciti.biz}/80
printf “GET / HTTP/1.0\r\n” >&3
printf “Accept: text/html, text/plain\r\n” >&3
printf “Accept-Language: en\r\n” >&3
printf “User-Agent: nixCraft_BashScript v.%s\r\n” “${BASH_VERSION}” >&3
printf “\r\n” >&3
while read LINE <&3
do
# do something on $LINE
# or send $LINE to grep or awk for grabbing data
# or simply display back data with echo command
echo $LINE
done