Showing posts with label Linux/Solaris. Show all posts
Showing posts with label Linux/Solaris. Show all posts

Tuesday, May 31, 2011

How to change crontab's default editor

I wanted to update a cron job in one of our server. As usual I entered crontab -e command. I was not able to edit it. The editor was not VI. Then I figured out it was using emacs editor.

To make vi default editor for crontab set EDITOR parameter to vi.

$ echo $EDITOR
/usr/bin/emacs

$ export EDITOR=vi

$ echo $EDITOR
vi



If still crontab uses emacs editor, then set VISUAL parameter also to vi:

$ echo $VISUAL
/usr/bin/emacs

$ export VISUAL=vi


$ echo $VISUAL
vi

Saturday, July 5, 2008

Password Expiration Notification

This is a simple script to notify about password expiration to users.

#!/bin/bash

# Set the environment variables
export ORACLE_HOME=/opt/oracle/product/102/DB
export ORALCE_SID=oradb
export PATH=$PATH:$ORACLE_HOME/bin

# Declar the vaiable
NOTIFY_LIST=user_name@abc.com
DIFF_FILE=/tmp/pass_exp.log

# Get expiry date
EXP_DATE=`chage -l oracle grep "Password Expires" awk '{print $4"-"$3"-"$5}'sed 's/,//'`

# Calculte in how many days password will expire
sqlplus usr/pass@$ORACLE_SID<<>
--CREATE TABLE pwd_expire (expire_date date);
INSERT INTO pwd_expire values (TO_DATE('$EXP_DATE','DD-MON-YYYY'));
COMMIT;
SET ECHO OFF FEEDBACK OFF
SPOOL $DIFF_FILE
SELECT ROUND(expire_date-sysdate) diff FROM pwd_expire;
SPOOL OFF
--DROP TABLE pwd_expire;
TRUNCATE TABLE pwd_expire;
EXIT

EOF

DAYS=`tail -2 $DIFF_FILEhead -1awk '{print $1}'`


if [ $DAYS -le 5 ]
then
mailx -s "Oracle Password will expires in $DAYS" $NOTIFY_LIST < /dev/null

fi






AXEL: Download accelerator for Linux

AXEL is a download accelerator for Linux. This utility also can be used to transfer files from one machine to another.

Download:
axel -n 16 -a http://download.com/download_file.gz

File Transfer:
axel -n 16 -a ftp://username/password@remote_host//temp/expdp_naikh_01.dmp

axel -n 16 -a ftp://username/password@remote_host//temp/expdp_naikh*

Saturday, March 29, 2008

Bash Shell Scripting Guide

1. Basics
a. The first line of the script must be
#!/bin/bash
b. Make the script exicutable
chmod +x test.sh

2. Conditional Statement
2.1. if statement
syntax:
if [ condition ]
then

commands
fi

2.2. if else statement
syntax:
if [ condition ]
then
commands
else
commands
fi

2.3. if elif statement
syntax:
if
[ condition1 ]
then
commands
elif [ condition2]
then

commands
else
commands
fi

3.1 Relational operators
-eg Equal to
-lt Less than
-gt Greater than
-ge Greater than or equal to
-le Less than or equel to

3.2 File Related Tests
-f file True if file exists and is a regular file
-r file True if file exists and is readable
-w file True if file exists and is writable
-x file True if file exists and is executable
-d file True if file exists and is a directory
-s file True if file exists and its size is greater than zero

3.3 String tests
-n str True if string str is not a null string
-z str True if string str is a null string
str1 == str2 True if both the strings are equel
str1 != str2 True if both the strings are not equel
str True if str is assigned a value and is not null

3.4 Multiple conditions
-a Performs the AND function
-o Performs the OR function

4. Case Statement
Syntax:
case expression in
pattert1) execute commands;;
pattert2) execute commands;;
pattert3) execute commands;;
....
esac

Example:
#!/bin/bash
case `datacut -d" " -f1` in
Mon) commands;;
Tue) commands;;
Wen) commands;;
....
esac

5. Looping Statements
5.1 while loop
syntax:
while [ condtion_is_true ]
do

execute commands
....
done

Example:
while [ $NUM -gt 100 ]
do
sleep
done

5.2 until loop
Syntax:
until [ condition_is_false ]
do
execute commands
done

Example:
until [ -f $FILE ]
do
sleep 5
done

5.3 for loop
Syntax:
for
variable in list
do
execute commands
done

Example:
for I in 1 2 3 4 5
do
echo "The value of I is $I";
done

Example 2:
#!/bin/bash
LIMIT=10
for ((a=1;a<=$LIMIT;a++)) do echo "$a" done
6. Special symbols
$0 Name of the shell script being executed
$1 First parameter passed to the script
$* All the paramerts passes to the script
$# Number of parameters passed to the script
$? Exit status of the last command

7. Read statement
#!/bin/bash
echo "Enter your name:"
read NAME
echo "Hello $NAME, Have a nice day."

8. Functions
Syntax:
Function_name ()
{
statements
}

Example:
#!/bin/bash
sumcalc ()
{
SUM= $[ $1 + $2 ]
echo "Result = $SUM"
}

echo -e "Enter the first number:\c"
read NUM1
echo -e "Enter the second number:\c"
read NUM2
read NUM2

# Call the function
sumcal $NUM1 $NUM2

Saturday, January 26, 2008

awk: Find & Replace

1. Single file - Replaces Oracle with Naikh
awk '{gsub("Oracle","Naikh",$0); print > FILENAME }' *.txt

2. Multiple Files - Replaces Oracle with Naikh
awk '{gsub("Oracle","Naikh",$0); print > FILENAME }' *.txt

3. All the file which contains a pattern
awk '{gsub("Oracle","Naikh",$0); print > FILENAME }' `find . exec grep -l "Oracle" {} \;

Note: Below command will not work
find . exec grep -l "Oracle" {} \; awk '{gsub("Oracle","Naikh",$0); print > FILENAME }'