This is an old revision of the document!
$ echo -n "Enter Name: "; read a; echo Hello $a $ sleep 3; echo -e "\007"
$ cat ex1.txt
echo -n "Enter Name: " read p echo Hello $p
$ sh ex1.txt $ . ex1.txt
$ cat ex1.sh
#!/bin/sh echo -n "Enter Name: " read p echo Hello "$p !!!"
$ chmod +x ex1.sh $ ex1.sh $ /home/userX/ex1.sh $ ./ex1.sh
$ mycd () {
> cd $1
> PS1="`pwd` $ "
> }
$ cat test_ping.sh
#!/bin/sh test -z $1 && exit 1 i=1 while [ $i -lt 254 ] do test $i = 50 && continue ping -c 1 -W 1 $1.$i > /dev/null 2>&1 && echo $1.$i i=$(($i + 1)) done
$ cat test_arp_ping.sh
#!/bin/sh test $# -lt 1 && exit 1 i=1 while : do ping -c 1 -W 1 $1.$i > /dev/null 2>&1 arp -an | grep "($1.$i)" | grep -q ':..:..:' && echo + $1.$i || echo - $1.$i i=$(($i + 1)) test $i -eq 254 && break done
for i in *sample; do cp $i ${i%.sample}; done
$ cat readifs.sh
#!/bin/sh IFS=: while read a b c d e f g do echo "$a $g" done < /etc/passwd
#!/bin/sh for i in `cut -d: -f1 /etc/passwd` do echo user $i done
$ cat trap.sh
#!/bin/sh
trap "echo got signal 2; date" 2
while : ; do
cat <<MENU
**********
* Exit ? *
* Yes *
* No *
**********
MENU
echo -n "Enter your choose: "
read a
case $a in
[Yy][eE][sS])
echo "Success"
exit 0
;;
*)
echo "Not Success"
;;
esac
done
Параллельное чтение двух файлов
$ cat report.sh
#!/bin/sh
exec 3<file1.txt
exec 4<file2.txt
exec 0<&3
while read a
do
exec 0<&4
read b
exec 0<&3
echo $a $b
done
$ cat log_gen.sh
while : do logger -t cisco -p local0.info "Message 1" logger -t cisco -p local0.info "Message 2" done
$ sh cisco_log_gen.sh
# cat /etc/rc
#!/bin/sh /usr/sbin/sshd
# cat /etc/init.d/ssh
#!/bin/sh
if [ "$1" = start ]
then
echo Starting sshd...
/usr/sbin/sshd
elif [ "$1" = stop ]
then
echo Stopping sshd...
kill -TERM `cat /var/run/sshd.pid`
while [ -e /var/run/sshd.pid ]
do
sleep 1
done
else
echo Usage:
echo "$0 start|stop"
fi
# cd /etc/init.d # ln -s ../init.d/ssh /etc/rc2.d/S10ssh # ln -s ../init.d/ssh /etc/rc0.d/K15ssh # ln -s ../init.d/ssh /etc/rc6.d/K25ssh # cat /etc/init.d/rc
#!/bin/sh
runlevel=$1
for s in /etc/rc${runlevel}.d/[SK]*; do
if test $s != ${s##/etc/rc${runlevel}.d/S??}
then
$s start
else
$s stop
fi
done
# chmod +x /etc/init.d/rc # /etc/init.d/rc 2 # /etc/init.d/rc 0
$ cat /etc/rc.d/sshd
#!/bin/sh
. /etc/defaults/rc.conf
. /etc/rc.conf
case "$sshd_enable" in
[Yy][Ee][Ss])
if [ "$1" = start ]
then
echo Starting sshd...
/usr/sbin/sshd
elif [ "$1" = stop ]
then
echo Stopping sshd...
kill -s TERM `cat /var/run/sshd.pid`
while [ -e /var/run/sshd.pid ]
do
sleep 1
done
else
echo Usage:
echo '/etc/rc.d/sshd start|stop'
fi
;;
esac
$ cat /etc/rc.conf
... sshd_enable=YES ...
$ cat /etc/rc
#!/bin/sh
for i in /etc/rc.d/*
do
$i $1
done
$ cat /etc/rc.conf
static_routes="wg1 wg2" route_wg1="10.10.10.0/24 10.10.106.100" route_wg2="10.10.20.0/24 10.10.106.100"
$ cat /etc/rc.d/routing
#!/bin/sh
. /etc/rc.conf
for i in ${static_routes}
do
eval route_arg=\$route_${i}
route add $route_arg
done
$ cat /etc/rc.conf
... ifconfig_fxp0="inet 10.5.2.17/24" ifconfig_fxp0_alias0="inet 10.5.2.18/32" ifconfig_fxp0_alias1="inet 10.5.2.19/32" ifconfig_fxp0_alias2="inet 192.168.15.1/24" ...
$ cat /etc/rc.d/netif
#!/bin/sh
. /etc/rc.conf
for intf in `ifconfig | grep mtu | cut -d: -f1`
do
eval args=\$ifconfig_$intf
if [ -n "$args" ]
then
ifconfig $intf $args
alias=0
while : ; do
eval ifconfig_args=\$ifconfig_${intf}_alias${alias}
if [ -n "${ifconfig_args}" ]
then
ifconfig $intf ${ifconfig_args} alias
alias=$((${alias} + 1))
else
break
fi
done
fi
done
$ echo a{1..5}b
$ echo a{1,3,5}b
# cat /usr/local/sbin/webd
#!/bin/bash
base=/var/www
read request
while :
do
read header
[ "$header" == $'\r' ] && break;
done
url="${request#GET }"
url="${url% HTTP/*}"
#test $url = "/" && url="/index.html"
filename="$base$url"
if [ -e "$filename" ]
then
echo -e "HTTP/1.1 200 OK\r"
echo -e "Content-Type: `/usr/bin/file -bi \"$filename\"`\r"
echo -e "\r"
/bin/cat "$filename"
else
echo -e "HTTP/1.1 404 Not Found\r"
echo -e "Content-Type: text/html;\r"
echo -e "\r"
echo -e "<h1>Not Found</h1>"
fi
# chmod +x /usr/local/sbin/webd
# mkdir /var/www # cat /var/www/index.html
<html> <h1>Hello from corpX</h1> <img src=img/logo.gif> </html>
# mkdir /var/www/img
# wget -O /var/www/img/logo.gif http://val.bmstu.ru/unix/Media/logo.gif
http://server.corpX.un/index.html
[radio:~] $ cat /usr/local/bin/internet.sh
#!/bin/sh
file=`mktemp -t ''`
dialog --title "Radio internet" --clear \
--checklist "Choose inet for rooms" 19 56 15 \
1 "Class 1" ON \
2 "Class 2" ON \
3 "Class 3" ON \
4 "Class 4" ON \
5 "Class 5" ON \
6 "Class 6" ON \
7 "Class 7" ON \
8 "Class 8" ON \
9 "Class 9" ON \
10 "Class 10" ON \
11 "Class 11" ON \
12 "Class 12" ON 2>$file
case $? in
0)
sed -i '' 's/"//g' $file
for i in `cat $file` 13 50 100 150 200 201 254
do
echo 10.5.${i}.0/24
done > /usr/local/etc/acl/radio_nets.acl
sudo /etc/rc.d/pf reload
;;
esac
rm $file
[radio:~] $ cat /etc/pf.conf
table <radio_nets> persist file "/usr/local/etc/acl/radio_nets.acl" table <squid_nets> persist file "/usr/local/etc/acl/squid_nets.acl" nat on dc0 from <radio_nets> to any -> (dc0) rdr proto tcp from <squid_nets> to !<radio_nets> port 80 -> 127.0.0.1 port 3128
[radio:~] # grep manager /usr/local/etc/sudoers
%manager ALL = NOPASSWD: /etc/rc.d/pf reload
sql="select uuid from accounts where uuid=\"$person_uuid\"" uuid=`mysql mybd -B --skip-column-names -e "$sql"` sql="update accounts set uuid=\"$person_uuid\" where uuid=\"$stage_uuid\"" mysql mybd -B --skip-column-names -e "$sql"
set +x set -n