LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 06-29-2006, 12:51 AM   #1
rammu_sivraj
LQ Newbie
 
Registered: May 2006
Posts: 15

Rep: Reputation: 0
Hi help me in scripts


This is my sample script
#!/bin/sh
# script to display file system packages and s/w packages
ech0 -e " system packages " >> /tmp/infoshell.sh
rpm -qa | sort | less >> /tmp/infoshell.sh
echo -e " file system profile " >> /tmp/infoshell.sh
df -a | cut -d" " -f1 >> /tmp/infoshell.sh
cat /tmp/infoshell.sh | more
rm -f /tmp/infoshell.sh

How to make the file infoshell.sh a userfriendly document?? the output of my script is so vague.
help me in viewing the o/p.. one should use tab key in scrolling down the o/p page.. plz help
Ramesh
 
Old 06-29-2006, 03:19 AM   #2
timmeke
Senior Member
 
Registered: Nov 2005
Location: Belgium
Distribution: Red Hat, Fedora
Posts: 1,515

Rep: Reputation: 61
A few tips:
1. Don't use "df" to get the names of the mounted partitions. Use "cat /etc/mtab" (piped into a similar cut) instead.
2. Maybe print some headers, to make the file more readable.
ie
Code:
echo "###########################" 
echo "###  Installed Packages ###"
echo "###########################"
#now do the rpm -qa
echo "###########################"
echo "### Mounted  partitions ###"
echo "###########################"
#now do the cat /etc/mtab or df stuff
3. Print to stdout, rather than to a file. This makes it possible to just print the result on your terminal. If needed, you can still simply redirect the output of your script into a file to save the results.

4. When storing text in a file, don't call it *.sh. People normally assume .sh files are executable shell scripts. Make it something like .txt or omit the file extension altogether (Linux doesn't rely on filename extensions to determine the file type).

5. Don't pipe the output of "rpm -qa | sort" through "less" or "more". "less" and "more" are designed for page-per-page reading of multi-page documents and expect user interaction (ie user should press a key to exit or to show the next page).

Edit: I'm not sure what you mean by "one should use the tab key in scrolling down". Please clarify this.
 
Old 06-30-2006, 12:18 PM   #3
archtoad6
Senior Member
 
Registered: Oct 2004
Location: Houston, TX (usa)
Distribution: MEPIS, Debian, Knoppix,
Posts: 4,727
Blog Entries: 15

Rep: Reputation: 233Reputation: 233Reputation: 233
6. Always spell "echo" 'echo' not 'ech0'.

7. Never write a name like "/tmp/infoshell.sh" more than once. Make it a variable like "INFO".
This cuts down on spelling errors causing problems, makes your code shorter & easier to read, and allows you to change the file name in one place (eliminates more spelling errors).
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
VPN: Debian Scripts -> Mandriva 2006 Scripts Undefined Mandriva 0 11-30-2005 01:10 PM
scripts demetriusp Programming 2 12-23-2004 09:18 AM
Need help running scripts from scripts sdouble Linux - Newbie 3 05-31-2004 01:56 PM
Scripts Thomzmaster Linux - Newbie 4 01-06-2004 02:57 PM
Scripts chamkila Linux - General 3 10-24-2002 02:34 PM


All times are GMT -5. The time now is 07:10 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration