This blog was created to improve my English and share news, thoughts and opinions about the world around me. I use it also to fix some technical solutions for future use.
giovedì 31 maggio 2012
Advanced Bash-Scripting Guide
Today I want to recommend an excellent manual on programming ofadvanced bash shell.
These are the links :
(html version) http://www.tldp.org/LDP/abs/html/
(pdf version) http://www.tldp.org/LDP/abs/abs-guide.pdf
Stay tuned
Bash shell script to see who is logged on or logged out every 3 seconds
Today a simple bash shell script to check every 3 seconds what user is logged in or logged out.
This script use "who" linux/unix command, result of these command is saved on a file that is checked every 3 seconds with new who execution :
#!/bin/bash
# + Giovanni Palleschi
# + 05/30/2012 13:23
# + Who is logged on or logged out every 3 seconds
echo 'The current time is:'
date
echo ' '
# List Current Users Connected
echo 'The current users are:'
who | cut -d' ' -f1 | sort -u > ./list_user_before
cat ./list_user_before
# Loop control login - logout every 3 seconds
while [ 1 ]; do
sleep 3
# List Current Users Connected
who | cut -d' ' -f1 | sort -u > ./list_user_after
# List of New Users Connected
echo ' '
diff ./list_user_before ./list_user_after | grep "^>" | cut -d' ' -f2 |
while read new_user_login
do
echo 'User' $new_user_login 'has logged in.'
echo ' '
done
# List of Users Disconnected
diff ./list_user_before ./list_user_after | grep "^<" | cut -d' ' -f2 |
while read new_user_login
do
echo 'User' $new_user_login 'has logged out.'
echo ' '
This script use "who" linux/unix command, result of these command is saved on a file that is checked every 3 seconds with new who execution :
#!/bin/bash
# + Giovanni Palleschi
# + 05/30/2012 13:23
# + Who is logged on or logged out every 3 seconds
echo 'The current time is:'
date
echo ' '
# List Current Users Connected
echo 'The current users are:'
who | cut -d' ' -f1 | sort -u > ./list_user_before
cat ./list_user_before
# Loop control login - logout every 3 seconds
while [ 1 ]; do
sleep 3
# List Current Users Connected
who | cut -d' ' -f1 | sort -u > ./list_user_after
# List of New Users Connected
echo ' '
diff ./list_user_before ./list_user_after | grep "^>" | cut -d' ' -f2 |
while read new_user_login
do
echo 'User' $new_user_login 'has logged in.'
echo ' '
done
# List of Users Disconnected
diff ./list_user_before ./list_user_after | grep "^<" | cut -d' ' -f2 |
while read new_user_login
do
echo 'User' $new_user_login 'has logged out.'
echo ' '
done
tot_users_diff=$(diff ./list_user_before ./list_user_after | wc -l)
if [ $tot_users_diff -eq 0 ]; then
echo 'No user has logged in/out in the last 3 seconds.'
fi
# Move file list user after in file user before for next control
mv -f ./list_user_after ./list_user_before
done
Stay tuned.
giovedì 17 maggio 2012
Ksh script to remove shared memory
Today a simple script to remove shared memory in ksh :
#!/bin/ksh
#
# Shell Script to remove shared memory MVNO Instance
#
PID=$(ipcs -m | grep 0x000000a[0-9a-b] | awk '{print $2}'|xargs)
for one_pid in ${PID}; do
ipcrm -m ${one_pid}
echo 'Removed shm : ' ${one_pid}
done
This script remove all shared memory from address 0x000000a0 to 0x000000ab. You must modify this expression to remove another shared memory.
Stay tuned.
#!/bin/ksh
#
# Shell Script to remove shared memory MVNO Instance
#
PID=$(ipcs -m | grep 0x000000a[0-9a-b] | awk '{print $2}'|xargs)
for one_pid in ${PID}; do
ipcrm -m ${one_pid}
echo 'Removed shm : ' ${one_pid}
done
This script remove all shared memory from address 0x000000a0 to 0x000000ab. You must modify this expression to remove another shared memory.
Stay tuned.
Iscriviti a:
Post (Atom)
Goals 2025
Hi all Today, first day of 2025 my goals for this year : 1. ENGLISH Improve listening comprehension See at least one or two films in Engli...
-
Hi all Today i want speak about education and eLearning websites. Personally I am using COURSERA , in this site you can find many course...
-
Hi all Today i want to speak about oracle nested table. Basically you can define in oracle a field that is a table inserted in other tabl...
-
Today a simple shell script to simulate rolls of two dices : #!/bin/ksh fc=1 while [ fc -eq 1 ]; do clear echo ' How many rolls : \c...