Improvement in shell script


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Improvement in shell script
# 1  
Old 06-13-2014
Improvement in shell script

Hi This is my Following code:

Code:
#!/bin/sh
echo "TOTAL_NO_OF_MAILS"
read TOTAL_NO_OF_MAILS
echo "TOTAL_NO_OF_TICKETS "
read TOTAL_NO_OF_TICKETS
echo "TICKETS_IN_QUEUE"
read TICKETS_IN_QUEUE
rm -rf `pwd`/Focus
echo "Hi Team\nSTATS IN CLRS MAIL BOX\n\n==============================" >> Focus
echo "#TOTAL_NO_OF_MAILS           :$TOTAL_NO_OF_MAILS\n#TOTAL_NO_OF_TICKETS CREATED :$TOTAL_NO_OF_TICKETS\n#TICKETS_IN_ASIA_QUEUE       :$TICKETS_IN_QUEUE" >> Focus
echo "==============================\n\nRegards\nClearSuite Support" >> Focus
mailx -r abc@abc.com -s "subjects" acb@abc.com  < Focus


*I am Getting input and mailing it.
*Its Working Fine!! Jus wanted to know is thr possibility of improvement in this code.
*The number of lnes must be minimum and code must be effective.

Awaiting for new ideas and suggestion to improve the code since i am very new to unix.

Last edited by wasim999; 06-13-2014 at 04:13 AM.. Reason: Add CODE tags.
# 2  
Old 06-13-2014
Is this a homework assignment?

After this script completes will anything else look at the data stored in ./Clearsuite and ./Focus?

What operating system are you using?
# 3  
Old 06-13-2014
Sorry there is nothing like clearsuitr.. it must be focuss.
As soon as mail is sent. the job is over.
operatin system is win 7
# 4  
Old 06-13-2014
The `pwd` means it relies on the output of an external program.
Better use . for "current directory", i.e. ./Focus or just Focus.
If you use a multi-line string, you can rewrite the file in one stroke, and also avoid a non-portable \n - and increase readability!
Code:
echo "\
Hi Team
STATS IN CLRS MAIL BOX

==============================
#TOTAL_NO_OF_MAILS           :$TOTAL_NO_OF_MAILS
#TOTAL_NO_OF_TICKETS CREATED :$TOTAL_NO_OF_TICKETS
#TICKETS_IN_ASIA_QUEUE       :$TICKETS_IN_QUEUE
==============================

Regards
ClearSuite Support" > Focus
mailx -r abc@abc.com -s "subjects" acb@abc.com  < Focus

Maybe you can omit the use of the Focus file by means of a pipe:
Code:
echo "...
..." |
mailx ...


Last edited by MadeInGermany; 06-19-2014 at 04:24 AM..
# 5  
Old 06-18-2014
Can u give a sample script for the above.. by using single echo statement.
# 6  
Old 06-19-2014
My last post has one consolidated echo.
(Just edited and converted last \n to a newline.)
# 7  
Old 06-19-2014
Quote:
Originally Posted by wasim999
*The number of lnes must be minimum and code must be effective.
What kind of measurement is this? I often end up writing a 100-line script to execute what is basically a oneliner. I add all sorts of checks (additional commands) and error handling (even more commands) to it, let the script write logs (more commands on top), but i don't suppose the script to be less good or less effective afterwards.

Of course i could execute the one core line instead and if everything works right it would effectively do the same as the 100-line script. Is the script ineffective therefore? Not at all.

So, what do you mean by "minimum number of lines"?

bakunin
These 2 Users Gave Thanks to bakunin For This Post:
 
Login or Register to Ask a Question

Previous Thread | Next Thread

7 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Performance improvement in grep

Below script is used to search numeric data from around 400 files in a folder. I have 300 such folders. Need help in performance improvement in the script. Below Script searches 20 such folders ( 300 files in each folder) simultaneously. This increases cpu utilization upto 90% What changes... (3 Replies)
Discussion started by: vegasluxor
3 Replies

2. Shell Programming and Scripting

I need the improvement for my script

Hi All, Here is my script #! /bin/sh var1=some email id var2=some email id grep -i "FAILED FILE FORMAT VALIDATION" /opt >tmp2 diff tmp1 tmp2 | grep ">" >tmp3 if then cat tmp3 | mailx -s " Error Monitoring" $var2 else echo "Pattern NOt Found" | mailx -s " Error Monitoring" $var1... (1 Reply)
Discussion started by: Gopalak
1 Replies

3. UNIX for Advanced & Expert Users

linux os improvement

can anyone help to share the knowledge on linux os improvement? 1) os account - use window AD authentication, such as ldap, but how to set /etc/passwd, where to put user home? 2) user account activity - how to log os user activity share the idea and what tools can do that...thx (5 Replies)
Discussion started by: goodbid
5 Replies

4. Shell Programming and Scripting

Looking for improvement to script that compresses a directory that is 2 months old

I write reports daily to a directory that is named with the month and year. I wanted to compress all but the last two months worth of these directories to save space. I am going to cron a job to run on the first of each month to do this clean up. I didn't have zip/unzip on my AIX environment so... (0 Replies)
Discussion started by: slatoms
0 Replies

5. Shell Programming and Scripting

Any improvement possible in this script

Hi! Thank you for the help yesterday This is the finished product There is one more thing I would like to do to it but I’m not to certain On how to proceed I would like to log all output to a log in order to Be able to roll back This script is meant to be used in repairing a... (4 Replies)
Discussion started by: Ex-Capsa
4 Replies

6. Shell Programming and Scripting

Script ready but might need some improvement.

Hi All, I have written a script which does some editing in the files, based on user input.This might not be the most elegant way of doing it and there would be many improvements needed. Please go through it and let me know how it could be improved. Suggestions are welcome!! Thanks!... (2 Replies)
Discussion started by: nua7
2 Replies

7. Programming

File - reading - Performance improvement

Hi All I am reading a huge file of size 2GB atleast. I am reading each line and cutting certain columns and writing it to another file. Here is the logic. int main() { string u_line; string Char_List; string u_file; int line_pos; string temp_form_u_file; ... (10 Replies)
Discussion started by: dhanamurthy
10 Replies
Login or Register to Ask a Question