LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Hi help me in scripts (https://www.linuxquestions.org/questions/linux-newbie-8/hi-help-me-in-scripts-459330/)

rammu_sivraj 06-28-2006 11:51 PM

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

timmeke 06-29-2006 02:19 AM

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.

archtoad6 06-30-2006 11:18 AM

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).


All times are GMT -5. The time now is 11:57 AM.