UnixTips.net

* use my tips at your own risk !!

* use my tips at your own risk !!

Categories

  • Other (3)
  • Scripting (10)
  • Unix (70)
  • Wordpress (2)

Powered by Genesis

Archives for February 2014

Unix Cron Crontab

#*    *    *    *    *      command to be executed
#-    -    -    -    -
#|    |    |    |    |
#|    |    |    |    +----- day of week (0 - 6) (Sunday=0)
#|    |    |    +---------- month (1 - 12)
#|    |    +--------------- day of month (1 - 31)
#|    +-------------------- hour (0 - 23)
#+------------------------- min (0 - 59)

Examples:

To run every minute:

* * * * * /path/to/my/script.sh

To run every x minutes:

*/10 * * * * /path/to/my/script.sh # every 10 minutes

To run every x hours:

# 5 hours and 0 minutes
0 */5 * * * /path/to/my/script.sh 

# 6 hours and 10 minutes :
10 */6 * * * /path/to/my/script.sh 

To run at midnight :

0 0 * * * /path/to/my/script.sh

awk : print column if it contains certain text

The following awk statement will print any user id that has a group id of 3.

In other words if the number in column 4 is a 3 , print column 1.

# awk -F: '{if ($4 =="3") print $1}' /etc/passwd
root
sys
uucp

$0 will print the entire line if the group id is 3.

# awk -F: '{if ($4 =="3") print $0}' /etc/passwd

If my file is a | for a field separator it will check for number 9 to match THIS and field number 11 to match that.
If it finds a patch it will print the fields 2 9 and 11.

awk "-F|" '{if ($9 == "THIS" && $11 == "THAT") print $2,$9,$11;}' /home/user/myfile

Need to add a variable

If my file is a | for a field separator it will check for the 2nd field to the variable host
If it finds a patch it will print the fields 20 in lower case letters.

# myhost=linuxprd1
# awk -v host=${myhost} "-F|" '{if ( $2 == host ) print tolower($20)}' /home/user/myfile

Solaris ssh in single usermode

Ever wish you could use ssh in single user mode? This may work some of the time.

From the console execute:

# /usr/lib/ssh/sshd

Then ssh to the server.

If you are running regular ssh this may work.

infinite ksh shell loop with count

So .. no thrills no frills. If you are searching for this .. you know what you are looking at and can modify this as needed.


#!/usr/bin/ksh

export PATH=$PATH:/sbin:/bin:/usr/bin:/usr/local/bin:/usr/sbin:/usr/local/bin

DATE=`date '+%Y.%m.%d_%H.%M.%S'`

count=1
while true
do
    echo ${count}
    (( count++ ))

if [[ ${count} -eq 11 ]]; then
    count=1

fi
sleep 1
done

This script will run forever and output:

1
2
3
4
5
6
7
8
9
10
1
2
3
4
5
6
7
8
9
10