November 22, 2024, 09:21:01 AM

News : LinuxSolved.com Linux Help Community Forum..


Author Topic: Hii. Help me in modifying my script  (Read 5865 times)

Offline rammu_sivraj

  • New Member
  • Posts: 2
Hii. Help me in modifying my script
« on: June 29, 2006, 06:23:07 AM »
# 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 a good o/p.. one should use tab key in scrolling down the o/p page.. plz help
Regards
Rammu

Offline dragoncity99

  • LST CareTaker
  • Experienced
  • *****
  • Posts: 551
Hii. Help me in modifying my script
« Reply #1 on: July 04, 2006, 06:07:29 AM »
# 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

Hi, i think, u'll need to re-organize ur script. It's a bit confusing to read ur script. :p

1. I suggest u do this as a good practice:

Quote

#!/bin/sh
# script to display file system packages and s/w packages

# Step 1 - Write the word " system packages " to file /tmp/infoshell.sh
echo -e " system packages " >> /tmp/infoshell.sh

# Step 2 - Write all the sorted rpm packages to file /tmp/infoshell.sh
rpm -qa | sort | less >> /tmp/infoshell.sh

# Step 3 - Write all th word "file system profile " to file /tmp/infoshell.sh
echo -e " file system profile " >> /tmp/infoshell.sh

# Step 4 - Write the disk usage to file /tmp/infoshell.sh
df -a | cut -d" " -f1 >> /tmp/infoshell.sh

# Step 5 - Read the file /tmp/infoshell.sh and display with "more"
cat /tmp/infoshell.sh | more

# Step 6 - Remove file /tmp/infoshell.sh
rm -f /tmp/infoshell.sh


2. Do not use "less" command in a script to redirect to a file. Omit the "less" command.
Code: [Select]
rpm -qa | sort | [b]less[/b] >> /tmp/infoshell.sh

3. Do not use file with "*.sh" file extension to represent a normal text file. It's a bit misleading.

That's my suggestion.

Cheers,
Dragon