Date: Fri, 27 Apr 2001 10:05:07 -0400 From: Paul Halliday <dp@penix.org> To: freebsd-hackers@freebsd.org Subject: hi. Message-ID: <3AE97C93.1E18434F@penix.org>
next in thread | raw e-mail | index | archive | help
This is a multi-part message in MIME format. --------------34C5FC0818788A40CBD56F0D Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit I am working on a little program and I am kinda stuck. I have attached it just in case what I say isn't clear. Basically I am having problems with the while loop in _monitor_state (line 129). For now I am using "trap _menu_state INT" which is most likely not right. I want to exit this function and enter _menu_state yet keep it running as a background process so that it is still recording data. What would be the proper way to access _menu_state, while not terminating the while loop in _monitor state? just a little push in the right direction would be appreciated. -- Paul Halliday Carpenter, Electrician. http://dp.penix.org Lesson of the week: dropping your PDA on a concrete floor is a bad thing. --------------34C5FC0818788A40CBD56F0D Content-Type: text/plain; charset=us-ascii; name="spike" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="spike" #!/usr/local/bin/bash # Lets begin.. # Initial system check. Take some records. What will we watch? for now lets # examine filesystem structure and sizes and monitor memory and cpu usage. We # will also determine how many users their is, what terminal they are on, and # what they are up to. Note: this is designed for smaller system setups. # Most of the checks that are performed will take far too much time and resources # to be practical on larger systems. ie. raid arrays, terabytes of # disk space etc. #---------------------------------------# _clean_up () { echo echo 'Caught SIGnal.. Exiting cleanly..' echo exit 1 # add stuff in here to cleanup working dirs. } trap _clean_up TERM #----------------------------------------# _first_state () { start=$date clear; echo "[ spike v.01b ]" echo echo "The first time this program is run it must aquire a fingerprint" echo "of the filesystem, this process will take about 5-10 minutes." echo "A full system fingerprint like this will be taken once every" echo -n "24 hours. " check=1 while [ $check = 1 ]; do echo -n "Do you wish to continue? [y/n]: " read comply case $comply in [Nn]) echo Quit!;exit 1;; [Yy]) check=2;; *) echo;echo -n "** Invalid entry! **"; sleep 1;_first_state;; esac done; _init_state } #---------------------------------------------------------------------# # somehow break down the fs into smaller chunks! _init_state () { echo -n "=> checking filesystem.. " echo "##### Archived: `/bin/date` #####" >spike.init /bin/ls -aliTR /root >>spike.init && chmod 600 spike.init && chflags schg spike.init; echo -n "done!" _usr_state } #----------------------------------------# _usr_state () { trap _menu_state INT echo "##### Archived: `/bin/date` #####" > $usf0 /usr/bin/who >>$usf0 echo " ">>$usf0 /bin/ps -aurx >>$usf0 && chmod 600 $usf0 _sys_state } #----------------------------------------# _sys_state () { echo "##### Archived: `/bin/date` #####" > $ssfwb; upt=(`/usr/bin/top -d 1 | sed -n 1p | tr -d ,`); echo "Load:${upt[5]} ${upt[6]} ${upt[7]}" >>$ssfwb; /usr/bin/top -d 3 0 | sed -n 18,20p >>$ssfwb; /bin/df -k >>$ssfwb; # check to see how many fs's are mounted and grab a cumlative total of free. # blocks. Ideally I would like to break it up for local and nfs but not now. hdf=(`/bin/df -k`); let hdc="${hdf[10]}"+"${hdf[16]}"+"${hdf[22]}"; echo "Blocks Available: $hdc" >>$ssfwb && chmod 600 $ssfwb; if [ $test -eq "0" ]; then cp $ssfwb $ssss && chmod 600 $ssss && chflags schg $ssss; test=1; fi; _cycle_state; } #----------------------------------------# _cycle_state () { # This gives us our intial numbers and keeps/logs them. Test will # return to its "0" state whenever records are sent out. if [ $test0 -eq "0" ]; then load[2]=`sed -n 2p $ssss| awk '{print $2}'`; cpu[2]=`grep CPU $ssss| awk '{print $11}'`; #mem[2]=`grep Mem $ssss| awk '{print $11}'`; hd[2]=`grep Available $ssss | awk '{print $3}'`; test0=1; fi # This parses the files created by the other functions and cycles them. load[1]=${load[0]} load[0]=`sed -n 2p $ssfwb | awk '{print $2}'` load[3]=$tload cpu[1]=${cpu[0]} cpu[0]=`grep CPU $ssfwb | awk '{print $11}'` cpu[3]=$tcpu # check to see if we are grabbing the right thing. checkmem=(`grep Mem $ssfwb`) ct=${#checkmem[*]} let trumem=$ct-2 mem[0]=${checkmem[$trumem]} mem[1]=${mem[0]} mem[3]=$tmem hd[1]=${hd[0]} hd[0]=`grep Available $ssfwb| awk '{print $3}'` hd[3]=$thd _monitor_state } #---------------------------------------------------------------------# # GUI! <- well not really _monitor_state () { quit=0; roll=`/bin/date "+%y.%m.%d% %H:%M:%S"` yu=("[current]" "[last]" "[start]" "[threshold]") while [ $quit=0 ]; do clear; echo " =====================================================[ Spike V0.1b ]====== Program start: $date Last refreshed: $roll =========================================================================== ${yu[0]} ${yu[1]} ${yu[2]} ${yu[3]} --------------------------------------------------------------------------- System load: ${load[0]} ${load[1]} ${load[2]} ${load[3]} CPU(idle): ${cpu[0]} ${cpu[1]} ${cpu[2]} ${cpu[3]} Memory(free): ${mem[0]} ${mem[1]} ${mem[2]} ${mem[3]} FS(free blks): ${hd[0]} ${hd[1]} ${hd[2]} ${hd[3]} Active users and process distribution: ---------------------------------------------------------------------------" echo -n "(^C for options - ^X to exit)" _usr_state done; } #---------------------------------------------------------------------# # Called by trap. Breaks while loop in _monitor_state. _menu_state () { clear; echo "-------(Options)------" echo echo "1) Mail Current record" echo "2) Modify thresholds" echo "3) Details on users" echo "4) Manage processes" echo "5) Return to output" echo "6) Leave Program" echo -n "=> " read opt case $opt in 5) echo "Returning to output..";; 6) echo "Exiting!"; exit 1;; *) echo "Invalid";; esac } ######################################### # Main # ######################################### # Check config file and setup variables. tload=50% tcpu=60% tmem=50% thd=10% # Resets test=0 test0=0 ssfwb=spike.dcm ssss=spike.start usf0=spike.user date=`/bin/date "+%y.%m.%d% %H:%M:%S"` echo "Please Wait.." _usr_state --------------34C5FC0818788A40CBD56F0D-- To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-hackers" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?3AE97C93.1E18434F>