Need help with shell scripts

chemistry_geek

Registered
I need help with creating a shell script for a project at work. I know this doesn't have anything to do with Macs, but I need a little direction to get this project going.

I just need to know when two text files "enterQ" (gets smaller over time) and "doneQ" (gets larger over time) haven't changed in 20 minutes.

Any help would be greatly appreciated! I just need to be pointed in the right direction to get this project started. I have a UNIX Shells book at work, but it is old. I'm working with Sun workstations running Solaris 8.
 
Are you familiar with C/C++, if so you may want to look into tcsh and csh scripting, the shell scripts or the tcsh and csh use similiar syntax to C. I think there is some tcsh stuff at the link below, you may find more support for bash scripting though.
http://www.shelldorado.com/links/
 
WeeZer51402 said:
Are you familiar with C/C++, if so you may want to look into tcsh and csh scripting, the shell scripts or the tcsh and csh use similiar syntax to C. I think there is some tcsh stuff at the link below, you may find more support for bash scripting though.
http://www.shelldorado.com/links/

No, I'm not familar with C/C++.

I remember asking if there was a shell script or sequence of commands that did the equivalent of "getinfo" in the Finder. I know that Panther has a "getinfo" command in the terminal now, but before that, it didn't exist. Someone replied with a series of commands that gave the file name, creation date, modification date, size, etc... but I can't find the thread. I've searched though the forums and can't find the thread. Perhaps it was lost during a site crash. Gosh, I even saved that hint. I'm at work now, and I know I have it saved somewhere. I think seeing a small script like that would help me. All I need to do then is rename a file, and compare size and modification date 20 minutes later IF the file is greater than a specified minimal size.

Anyone know how to do a "getinfo" using shell commands?
 
just make sure you run chmod u=rwx on this file, i hope it does what you want it to, to use it just run it like any other unix command "getinfo /path/to/file". Good Luck!
Code:
#!/bin/bash
echo "Current Working Directory is $PWD"
ls -al | grep "$1"
 
WeeZer51402 said:
just make sure you run chmod u=rwx on this file, i hope it does what you want it to, to use it just run it like any other unix command "getinfo /path/to/file". Good Luck!
Code:
#!/bin/bash
echo "Current Working Directory is $PWD"
ls -al | grep "$1"


Thank you for the help. I'll have to try this when I get home.
 
I tried the script, it doesn't do what I want it to do. I was digging around the Apple Developer CD that comes with Panther. In order for me to get the "GetFileInfo" shell script/executable, I have to install the full Developer tools. I only have 2GB left on my HD, and the install requires 1.5GB. Guess I'll have to go without for a while until I can clear off some more stuff. I found the man page for it by using "locate GetFileInfo" and the path for the man page comes up, but no path for the command.
 
Initially, I wanted a script to extract from a file that I name, the size of the file and last time it was modified. Then I remembered that someone posted a command line equivalent to "Get Info" in the Finder. I've searched the forums and can't find the thread. I thought I could piece some code together to do what I need it to do. I just need a script to determine whether or not a text file has anything in it, if it does, then the script needs to check the last time it was modified, let's say 20 minutes. If the file is empty, the script does nothing, other than check the text file again in 20 minutes via running as a cron job. The reason I'm doing this is for a project at work. Part of my job is to maintain four Open Access (anyone can use the equipment) NMR laboratories. The Varian NMR instruments (http://www.varianinc.com/cgi-bin/nav?products/nmr/index&cid=IJQMIQJFO) are controlled by Sun Microsystems workstations running Solaris 8. These instruments are completely automated (http://www.varianinc.com/cgi-bin/nav?products/nmr/accessory/auto_samplers/sms/index&cid=IJQMIJLFP) with very fast robotics. A previous employee wrote a series of shell scripts that does quite a bit more, sorry I don't want to say what they do for fear of breach of confidentiality. Pharmaceutical companies are very protective of methods developed in-house to streamline, make research more efficient, and less costly. Occasionally, this Varian software just silently stops running and no experiments are running-that costs A LOT OF MONEY WHEN THEY SIT IDLE, I suggested to my supervisor that a shell script be written that runs as a cron job to check a text file over a specified time frame. The script's job is to detect when the Varian automation software and hardware hangs up. Code already exists in other shell scripts on what to do when an error occurs.

Late Friday afternoon my supervisor said that if I can't write the code, he can find someone who can, he just needs from me a logic diagram of the program to give to someone else. And I can't post a diagram here without giving away other parts of the custom shell scripts that do everything else. I'm stuck between a rock and a hard place. I don't want to depend too much on other people, because this is a good learning experience, and I want to do as much of it myself as I can. I like programming, I just don't know enough about C/C++ or shell scripts.

About 14 years ago, I wrote a report generator for the hospital department I was working in, to finance my college education. The medical reports up to that time were recorded on dictation equipment, and a secretary had to listen to the dictation cassettes and type EVERYTHING on the tape. I said "I can make this whole process much more efficient", not even knowing if I could do it. One year later, a magnificent series Word Perfect Macros, the "Report Generator" was completed. My supervisor implemented it, report turn-around times decreased substantially, reports were made more efficiently, Vice Presidents were notified, and hospital programmers used my Report Generator as a model for other departments. In the end, I got an excellent job review, a letter of commendation placed in my employee file, and I was the "wiz kid" of the department until I left.
 
hey, put the following code into a file called checkq.sh.


Code:
#!/bin/bash 

el1=`cat lastenterq`
dl1=`cat lastdoneq`

# this assumes you are only looking for line changes.  not changes in lines.  
# use bin/diff for that 
el0=`wc -l enterq|awk '{print $1}'`
dl0=`wc -l doneq|awk '{print $1}'`

# of  course, you prolly want to get an email or something. 
if [ $dl1 == $dl0 ] ; then echo "Done q has not changed in 20 minutes" ; fi
if [ $el1 == $el0 ] ; then echo "Enter q has not changed in 20 minutes" ; fi

echo `wc -l doneq|awk '{print $1}'` > lastdoneq
echo `wc -l enterq|awk '{print $1}'` > enterdoneq

then add this to your crontab by doing "crontab -e"
Code:
0,20,40 * * * * checkq.sh

make sure your paths are good ... and chmod +x checkq.sh and you should be good to go. oh, this will run on any *nix os i figure.


chemistry_geek said:
I need help with creating a shell script for a project at work. I know this doesn't have anything to do with Macs, but I need a little direction to get this project going.

I just need to know when two text files "enterQ" (gets smaller over time) and "doneQ" (gets larger over time) haven't changed in 20 minutes.

Any help would be greatly appreciated! I just need to be pointed in the right direction to get this project started. I have a UNIX Shells book at work, but it is old. I'm working with Sun workstations running Solaris 8.
 
Thank you very much for the reply. I will give this script a try. I learned earlier this week that Solaris uses the Bourne shell, don't know if that makes a difference. Prolly so. Also, I been thinking of some other features to add to the script in which case this shell script project will likely be handed off to one of the site programmers.
 
Back
Top