Help! Basic shell script advice


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Help! Basic shell script advice
# 1  
Old 05-11-2012
Data Help! Basic shell script advice

#####

Last edited by AidoPotato; 05-29-2012 at 09:47 PM.. Reason: code tags
# 2  
Old 05-11-2012
Welcome to the forum.
You have done a good job of writing the script as a learner.

There are some points you could make a note of.
1) repetitive execution of the same commands should be avoided.
2) redundant code should be avoided.
3) printLogoffs and printLogons functions seems to be no use in your case. those are just printing the difference of the files which you already stored.
4) wc would print newlines, words, and bytes for the files. In your case you are taking words (lines should be more safer I guess)
5) print on screen and redirecting to the file both can be achieved on one command with tee. look for it.

Code:
who | /bin/awk '{ print $1 }' > check1        #create file to store user details
sort check1                                 #display users
sort check1 > userlist1                     #stored outside loop so it doesn't renew every loop

Could be written as

Code:
who | /bin/awk '{ print $1 }' | sort | tee userlist1


Code:
wc changesQueryLogoffs | awk '{print $2}'

Could be written as

Code:
wc -w < changesQueryLogoffs #count words (as in your command)
wc -l  < changesQueryLogoffs  #count lines


For printing just the differences ( logon and logoff functions) you could just cat the files. Ditto for logon.

Code:
echo "***Following user(s) logged out.***"
cat changesQueryLogoffs

Hope it helps.
This User Gave Thanks to clx For This Post:
# 3  
Old 05-11-2012
Computer THANKS!

Oh man i feel a bit stupid haha ive fixed up a lot of stuff, including your recommendations! Thanks a lot!

I have experience with java but shell scripting was like chalk and cheese haha!
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Basic Shell script - Not working

Hello, This is basic (i think). I am trying to run a shell script which would go into each folder (folder names defined in the list) and after entering would run some commands, once done, come out of the folder and continue until the list ends. Pretty basic and there are bunch of example online. ... (9 Replies)
Discussion started by: Zam_1234
9 Replies

2. Shell Programming and Scripting

Advice required shell script

Hi all, this is my first post, so please be gentle... I have a situation wherby I need a script that traverses known paths. Check for the modified date (n days) and then deletes all subdirs. I have come up with this hotch potch, but as far as I can tell it seems to work. What I am wondering... (4 Replies)
Discussion started by: primus7
4 Replies

3. Shell Programming and Scripting

Basic shell script help

Im trying to make a script that simply adds a word to the last available line in a txt file without overwriting any previous lines. Ive googled this and there are great examples but no one explain what each function does, and i dont entirely understand how it works. Basically Im looking for... (7 Replies)
Discussion started by: kylecn
7 Replies

4. Shell Programming and Scripting

Basic Shell Script Help

Lets say I wanted to create a script that would show what people are doing on my machine using the w command and refresh in about 6 seconds. What would be the easiest way to do this? I pretty much want the script to loop until I stop it. I'm using the BASH shell by the way. Help is appreciated.... (1 Reply)
Discussion started by: c4391
1 Replies

5. UNIX for Advanced & Expert Users

Career advice for experienced shell script coder, need help.

I have four years of shell scripting experience in AIX and HP-UX and have worked in perl scripts as well, the good part is i love scripting and so far i have been getting job offers as well. The bad part is , shell scripting is all i know , so the kind of jobs i am getting is mostly production... (2 Replies)
Discussion started by: harishrao
2 Replies

6. Shell Programming and Scripting

shell script basic doubt

hi, I am new script learner, so my basic doubt is , how to store value of any command in a variable example $ ls | wc -l i want to stote the output of this in a variable c. so that i can use c in if else loop. and when do we use " ` " symbol in script.. can anyone also tell for... (5 Replies)
Discussion started by: hi2_t
5 Replies

7. Shell Programming and Scripting

advice on shell script

Hello, I have this script running on cron every 20 minutes. By 12pm daily, our system is expecting all input files to be uploaded by the script. After this cutoff time, the script would still be running though, but i need some kind of alerts/logs to know which input files weren't received for... (1 Reply)
Discussion started by: gholdbhurg
1 Replies

8. Shell Programming and Scripting

Basic Shell script syntax help

Hi All, I am new to shell scripting. I have a variable which holds a numeric value.I have to check whether this variable holds a value between(0- 8),(8-17)(17-24).How do i write this syntax using if in shell scripting. Thanks Vignesh (2 Replies)
Discussion started by: vignesh53
2 Replies

9. Shell Programming and Scripting

need a quick basic shell script help

im trying to run the below if command ifconfig -a |grep 10.100.120.21 gives me below output inet addr:10.100.120.21 Bcast:10.100.120.255 Mask:255.255.255.0 i just want a basic shell which says if above exists then continue how would i do this? (6 Replies)
Discussion started by: eb222
6 Replies

10. Shell Programming and Scripting

c-shell script advice please.

Hi, I have the following script running in my cron. -------------------------------------------------------------------- #!/bin/csh bnstat -p GPD_VSLinux | grep pg | grep varcon | awk '{print $1, $2, $3, $4, $5, $6, $7, $8, $9, $10}' > /tmp/LX_xbatch.log bnstat -p GPD_VSLinux_test | grep pg... (2 Replies)
Discussion started by: killerserv
2 Replies
Login or Register to Ask a Question