grep and assign it's output to variables inside script itself problem
ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
if [ "$1" = "-h" -o "$1" = "--help" ];then
echo "Blah blah blah"
exit 0
fi
if [ "$#" -ne 3 -o ! -d "$1" ];then
echo $USAGE
echo "Try `basename $0` --help for more options."
exit 0
fi
echo "Checking User"
sleep .91
if [ "$UID" -eq "$ROOT_UID" ]
then
echo "You are root. OK"
else
echo "Please run this script as a root user to complete task"
echo "Aborting...."
exit 0
fi
echo "Checking gfs mount."
sleep .91
mount |grep "gfs" >/dev/null
if [ "$?" -ne 0 ] ;then
echo "File system GFS is not mounted, Please mount GFS file system."
echo "Exiting..."
exit 0
else
echo "Found mounted GFS. OK"
fi
if [ ! -d $RESULTS ];then
echo "Creating directory to store test results."
sleep 1
mkdir $WORK_DIR/results
fi
if [ ! -d $LOG_DIR ];then
echo "Creating log diretory."
sleep 1
mkdir $WORK_DIR/log
fi
echo "Performing initial tests of nodes before performing our test suite of failing nodes in different scenarios. be patience"
echo "Checking the secure shell access to the storage nodes $2 $3 ."
for i in "$2" "$3" ;do
sleep 2
echo hi |nc "$i" 22 >/dev/null
echo
echo "Good secure shell port found open on storage node $i"
echo
echo "Now checking remote command execution on storage node $i"
echo "=================================================================================================== ================"
echo -e "$i should not prompt for password , in case it asks then generate id-dsa public key $HOSTNAME:/root/.ssh/id_dsa.pub on this machine with command\n ssh-keygen -t dsa with an empty password and copy it in $i:/root/.ssh/authorized_keys "
echo "=================================================================================================== ================="
echo
echo
sleep 1
echo "******** This is our storage node $i. *********"
echo
ssh $i uname -a
if [ "$?" -ne 0 ];then
echo "Sorry contact your network admin to make sure node $i port 22 is accessible to this machine $HOSTNAME."
echo "Errror remote command execution. Initial condition to perform our test did not met. Node $i is not accessible over secure shell port 22. "
exit 143
fi
done
################## raid section #######################
raid_disks () {
ssh $1 mdadm --examine --scan |grep ,|cut -d = -f2| sed 's/,/ /g';
}
DISKS=(`raid_disks $2`)
echo Found ${DISKS[1]}
echo Found ${DISKS[2]}
echo Found ${DISKS[0]}
echo Found ${DISKS[@]}
DISKSB=(`raid_disks $2`)
echo Found ${DISKSB[1]}
echo Found ${DISKSB[2]}
echo Found ${DISKSB[0]}
echo Found ${DISKSB[@]}
echo -e "Remote command execution over storage nodes $2 $3 test OK. \n"
sleep 2
select i in "kernel install and file I/O reports" "Only file I/O reports" "exit"
do
case $i in
kernel*) echo "You have selected to install the downloaded kernel as well to generate reports."
ANSWER=0
break ;;
Only*) echo "Only reluts will be generated, no kernel will be installed."
ANSWER=1
break;;
exit) echo "Aborting..."
exit 0;;
*) echo "Please select a number from the menu" ;;
esac
done
if [ "$?" -ne 0 ] ;then
echo "You dont have direct access to internet. Please contact your network administrator."
echo -e "[`date`] You don't have direct internet access to download test suites. contact network administrator" >>$ERR
exit 0
else
echo "Internet access checked. OK"
echo "Now downloading test kernel file."
cd $WORK_DIR
wget -c $KERNEL_URL
tar jxvf $WORK_DIR/linux-2.6.22.6.tar.bz2 >/dev/null
cd linux-2.6.22.6
make allyesconfig
make
sudo make modules_install install
fi
echo "Now downloading and installing iozone."
cd $WORK_DIR
echo $PWD
wget -c $IOZONE_URL
echo "Installing iozone test suite"
tar xvf iozone3_283.tar
cd $WORK_DIR/iozone3_283/src/current/
echo "[`date`]==========iozone installation===========" >>$ERR
make linux 2>>$ERR
if [ "$?" -ne 0 ];then
echo "installation of iozone test suite failed , Please check log $ERR for more details"
else
echo "iozone is installed"
echo -e "[`date`] iozone is installed successfully in $PWD \n" >>$ERR
echo "Running the iozone test on downloaded file, this may take significant time."
echo "[`date`]==========iozone test startup==========" >>$ERR
cd $WORK_DIR
if [ -f linux-2.6.22.6.tar.bz2 ];then
echo "Starting iozone test."
$WORK_DIR/iozone3_283/src/current/iozone -ec -r 4 -r 16 -s 32m -s 256m -s 2G -i 0 -i 1 -i 2 -i 8 -b $RESULTS/output_iozone.wks -f $WORK_DIR/linux-2.6.22.6.tar.bz2 2>>$ERR
echo "Results are stored in $RESULTS/output_iozone.wks file."
echo -e "[`date`]*****Test iozone completed***** result is stored in $RESLULTS/ouput_iozone.wks \n" >>$ERR
else
echo -e "[`date`]File does not exist linux-2.6.22.6.tar.bz2" >>$ERR
echo "Test file does not exist. Check $ERR"
exit 0
fi
fi
echo "********Starting fsx test*********"
echo "installing fsx now."
cd $WORK_DIR
echo $WORK_DIR
wget -c $FSX_URL
tar zxvf ltp-full-20070731.tgz
find $WORK_DIR/ltp-full-20070731/ -name "*fsx-linux*.c" -exec cc -o fsx {} \;
$WORK_DIR/fsx -WR -S 0 -l 10000000 -o 1000000 -c 100 -N 10000 -d $WORK_DIR/linux-2.6.22.6.tar.bz2 2>>$ERR
cp -f *.fsx* $RESULTS/
echo "[`date`]fsx results are stored in $RESULTS dir. `ls -l *.fsx*`">>$ERR
echo -e "************* fsx test completed ***************">>$ERR
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.