enter_cont () {
echo "Press Enter to continue"
read ans
}
top_proc () {
tput clear
ps aux | grep -v kproc | head -15
echo "Press Enter to continue"
read ans
}
dup_check () {
clear
cmp $outputfile $pwd
echo "Press Enter to continue"
read ans
}
check_exe () {
clear
find $HOME -type f -perm -g+rx
echo "Press Enter to continue"
read ans
}
date_check () {
clear
echo "The date is"
echo "`date`"
echo "$outputfile"
echo "$outputfile2"
echo "Press Enter to continue"
read ans
}
file_dir () {
clear
if [ -f $outputfile ];
then
echo "File [$outputfile] exists"
else
echo "File [$outputfile] does not exists"
fi
if [ -d $outputfile2 ];
then
echo "Directory [$outputfile2] exits"
else
echo "Directory [$outputfile2] does not exist"
fi
if [ -f $outputfile ] && [ -d $outputfile2 ];
then
cp $outputfile $outputfile2
echo "[$outputfile] file has been copied to directory [$outputfile2]"
fi
echo "Press Enter to continue"
read ans
}
search_proc () {
outputfile3=$3
clear
echo 'Type Proccess name to search for then press ENTER '
ps -ewwo pid,args | grep $outputfile3 | awk '{print $1}'
}
outputfile=$1
outputfile2=$2
if [ $# -eq 0 ]
then
echo "You must enter a filename"
exit
fi
until [ -n "$validchoice" ]
do
tput clear
echo " ~~~~~~~~~~~~~~~~~~~~~"
echo " M A I N - M E N U"
echo " ~~~~~~~~~~~~~~~~~~~~~"
echo " 1) Show top 15 processes (CPU)"
echo " 2) Check for duplicates"
echo " 3) Check for executables in current dir"
echo " 4) Date"
echo " 5) Check file and directory"
echo " 6) Search Processes"
echo " x) Logout"
read choice;echo
case $choice in
1) top_proc;;
2) dup_check;;
3) check_exe;;
4) date_check;;
5) file_dir;;
6) search_proc;;
x) validchoice=TRUE;;
*) echo "Invalid option";enter_cont;;
esac
done
The problem is
I need it too go from the main menu by pressing 6, to the submenu search_proc. In the search_proc menu/section it need to accept a variable and search the processes for it and sort by PID and Process name. I'm stuck and ran out of ideas. I also cannot figure out why it keeps flashing quick and going back to the main menu.
yazu
June 8, 2011, 10:35pm
2
Inside a function positional parameters are setted with new values, so your $outputfile is null:
#!/bin/sh
# Usage: ./this_script a b
f() {
echo $1 $2
}
echo $1 $2
f x
I hope you get the idea.
I'm still confused to be honest. I need it to change to the new menu, then accept the input so i can use it for my grep command.