Bash Shell script to check the existence of a file under your linux filesystem August 3, 2010
Posted by networknuts in Uncategorized.Tags: bash shell scripting, delhi linux, linux delhi, linux training, Network NUTS, redhat, redhat linux, rhce, rhce delhi, rhce india, rhcss, rhcss delhi, rhcss india, rhcva, shell scripting, training
1 comment so far
Here is a very small but useful shell script that will check the existence of a file and report accordingly.
#!/bin/bash
#by alok srivastava
#check the existence of a file under your filesystem
#this bash shell script use "positional parameters"file=$1
[ $# -eq 0 ] && { echo "Usage: $0 filename"; exit 999; }
if [ -f $file ];
then
echo "YES - File $file exists."
else
echo "NO - File $file does NOT exists."
fi
It can be very useful while creating more complex bash shell scripts.
Here is a sample execution shown for your reference:
Shell Script taking Time bound Input !! May 13, 2010
Posted by networknuts in Uncategorized.Tags: linux shell scripting, Network NUTS, networknuts.net, rhce delhi, rhce india, rhcss india, shell scripting, shell scripting course, shell scripting course delhi, shell scripting delhi
add a comment
Here is a simple shell script that will take the input from user keyboard and displays it on the screen. But the idea is not that!!!
Idea is to show you, how to take “time bound” input for sensitive information.
vim timed_read.sh
and here is the script…
#!/bin/bash
#alok srivastava
#taking time bound inputTIMEOUTLIMIT=4 # 4 seconds of wait
echo “type something “
read -t $TIMEOUTLIMIT first <&1
echoif [ -z "$first" ]
then
echo “timed out.. sorry”
else
echo “you typed $first”
fiexit 0 # exit clean
When you execute this script using “sh time_bound.sh” and give some input within the time frame of 4 seconds it will be displayed.. else the script will exit cleanly after waiting for 4 seconds. As shown:
God Bless.
