Character validation in shell script?

scmuser created the topic: character validation in shell script?
Write shell code to accept a string from the terminal, and echo a suitable message if it does not have at least 10 characters using (i) case (ii) expr.

Tagged :

Make sure script is running using korn shell

scmuser created the topic: Make sure script is running using korn shell

If you have developed a script using the Korn shell, how will you make sure the script will use that shell even if login shell is different?

renjith replied the topic: Re: Make sure script is running using korn shell

begin shell script with Shabang/interpreter line

#!/bin/ksh

rajeshkumar replied the topic: Re: Make sure script is running using korn shell

There are 2 ways to run a script with specific shell no matter if login shell is different..

Method 1:
Use following before any shell script…
#!/bin/ksh

Method 2:

Execute shell script with ksh
Regards,
Rajesh Kumar
Twitt me @ twitter.com/RajeshKumarIn

Tagged :

Identical file validation using shell script?

scmuser created the topic: identical file validation using shell script?

Device a script that accepts two directory names, bar1 and bar2, and deletes those files in bar2 which are identical to their namesakes in bar1.

rajeshkumar replied the topic: Re: identical file validation using shell script?

Solution:

#!/bin/bash
cd $1
for file in * ; do
if [ -f ../$2/$file ] ; then
cmp $file ../$2/$file >/dev/null 2>/dev/null && rm ../$2/$file
fi
done

Regards,
Rajesh Kumar
Twitt me @ twitter.com/RajeshKumarIn

Tagged :

Shell script that will add two nos, which are supplied as command line

scmjobs created the topic: Shell script that will add two nos, which are supplied as command line
How to write shell script that will add two nos, which are supplied as command line argument, and if this two nos are not given show error and its usage

Tagged :

Write Script, using case statement to perform basic math operation

scmjobs created the topic: Write Script, using case statement to perform basic math operation

Write Script, using case statement to perform basic math operation as
follows
+ addition
– subtraction
x multiplication
/ division
The name of script must be ‘q4’ which works as follows
$ ./q4 20 / 3, Also check for sufficient command line arguments

Tagged :

Run php script using cronjob / crontab

scmuser created the topic: Run php script using cronjob / crontab
How can i Run php script using cronjob / crontab???

Any ideA?

rajeshkumar replied the topic: Re: Run php script using cronjob / crontab
If your PHP scripts do have executable permissions like 755 or -rwxr-xr-x and they have one of the PHP filename extensions above, then you do not need to specify the php interpreter in the command portion of your cron line, like this:

5 17 * * 2 /myscript.php

The above cron would run myscript.php in your home directory every Tuesday at 5:05PM.

some more example…

28 14 * * * /usr/local/bin/php -q /myscript.phtml
6 3 20 4 * /usr/local/bin/php -q /htdocs/www/x.php
Regards,
Rajesh Kumar
Twitt me @ twitter.com/RajeshKumarIn

Tagged :

Shell Script that will add two nos

rajeshkumar created the topic: Shell script that will add two nos
How to write shell script that will add two nos, which are supplied as command line argument, and if this two nos are not given show error and its usage


#!/bin/bash
#
# Linux Shell Scripting Tutorial 1.05r3, Summer-2002
#
# Written by Vivek G. Gite
#
# Latest version can be found at www.nixcraft.com/
#
# Q1.Script to sum to nos
#

if [ $# -ne 2 ]
then
echo "Usage - $0 x y"
echo " Where x and y are two nos for which I will print sum"
exit 1
fi
echo "Sum of $1 and $2 is `expr $1 + $2`"
#
# ./ch.sh: vivek-tech.com to nixcraft.com referance converted using this tool
# See the tool at www.nixcraft.com/uniqlinuxfeatures/tools/
#


Regards,
Rajesh Kumar
Twitt me @ twitter.com/RajeshKumarIn

Tagged :

Script to find out biggest number from given three nos

rajeshkumar created the topic: Script to find out biggest number from given three nos

Write Script to find out biggest number from given three nos. Nos are supplies as command line argument. Print error if sufficient arguments are not supplied.


#!/bin/bash
#
# Linux Shell Scripting Tutorial 1.05r3, Summer-2002
#
# Written by Vivek G. Gite
#
# Latest version can be found at www.nixcraft.com/
#
# Q2. Script to find out bigest number
#
# Algo:
# 1) START: Take three nos as n1,n2,n3.
# 2) Is n1 is greater than n2 and n3, if yes
# print n1 is bigest no goto step 5, otherwise goto next step
# 3) Is n2 is greater than n1 and n3, if yes
# print n2 is bigest no goto step 5, otherwise goto next step
# 4) Is n3 is greater than n1 and n2, if yes
# print n3 is bigest no goto step 5, otherwise goto next step
# 5) END
#
#

if [ $# -ne 3 ]
then
echo "$0: number1 number2 number3 are not given" >&2
exit 1
fi
n1=$1
n2=$2
n3=$3
if [ $n1 -gt $n2 ] && [ $n1 -gt $n3 ]
then
echo "$n1 is Bigest number"
elif [ $n2 -gt $n1 ] && [ $n2 -gt $n3 ]
then
echo "$n2 is Bigest number"
elif [ $n3 -gt $n1 ] && [ $n3 -gt $n2 ]
then
echo "$n3 is Bigest number"
elif [ $1 -eq $2 ] && [ $1 -eq $3 ] && [ $2 -eq $3 ]
then
echo "All the three numbers are equal"
else
echo "I can not figure out which number is biger"
fi

#
# ./ch.sh: vivek-tech.com to nixcraft.com referance converted using this tool
# See the tool at www.nixcraft.com/uniqlinuxfeatures/tools/
#


Regards,
Rajesh Kumar
Twitt me @ twitter.com/RajeshKumarIn

Tagged :

Write script to print nos as 5,4,3,2,1 using while loop

rajeshkumar created the topic: Write script to print nos as 5,4,3,2,1 using while loop

Write script to print nos as 5,4,3,2,1 using while loop.

#!/bin/bash
#
# Linux Shell Scripting Tutorial 1.05r3, Summer-2002
#
# Written by Vivek G. Gite
#
# Latest version can be found at http://www.nixcraft.com/
#
# Q3
# Algo:
# 1) START: set value of i to 5 (since we want to start from 5, if you
# want to start from other value put that value)
# 2) Start While Loop
# 3) Chechk, Is value of i is zero, If yes goto step 5 else
# continue with next step
# 4) print i, decement i by 1 (i.e. i=i-1 to goto zero) and
# goto step 3
# 5) END
#
i=5
while test $i != 0
do
echo "$i
"
i=`expr $i - 1`
done
#
# ./ch.sh: vivek-tech.com to nixcraft.com referance converted using this tool
# See the tool at http://www.nixcraft.com/uniqlinuxfeatures/tools/
#

Regards,
Rajesh Kumar
Twitt me @ twitter.com/RajeshKumarIn

Tagged :