LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
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 10-04-2006, 02:43 PM   #1
lorio
LQ Newbie
 
Registered: Aug 2002
Location: CANADA
Distribution: Slackware
Posts: 10

Rep: Reputation: 0
How to create a Create script "easier"?


Hi guys! It's my first script that I've done for the servers I work on. These are VMware ESX commands but at the end it's all Linux. I was wondering... is there a way to make all this script "easier"?

Code:
echo 
echo "Please wait while creating" `hostname`".txt file..."
echo
uname -a > `hostname`.txt
echo  >> `hostname`.txt
vmkmultipath -q >> `hostname`.txt
echo "..................................................." >> `hostname`.txt
mii-tool eth0 >> `hostname`.txt
echo "..................................................." >> `hostname`.txt
vdf -h >> `hostname`.txt
echo "..................................................." >> `hostname`.txt
ls -l /vmfs >> `hostname`.txt
echo "..................................................." >> `hostname`.txt
echo "Swap" >> `hostname`.txt
echo >> `hostname`.txt
cat /proc/swaps >> `hostname`.txt
echo "..................................................." >> `hostname`.txt
echo "Registered VM's" >> `hostname`.txt
echo >> `hostname`.txt
vmware-cmd -l >> `hostname`.txt
echo "..................................................." >> `hostname`.txt
echo "VMware Licences : " >> `hostname`.txt
echo >> `hostname`.txt
cat /etc/vmware/license-2-0.esx.2.0 >> `hostname`.txt
echo >> `hostname`.txt
echo "SMP :" >> `hostname`.txt
echo >> `hostname`.txt
cat /etc/vmware/license-2-2.esx-smp.2.0 >> `hostname`.txt
echo "..................................................." >> `hostname`.txt
 
Old 10-04-2006, 02:48 PM   #2
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985
easier?? it's certianly a lot nicer without all those full stops in it.. yuck!

really not sure what you mean by easier.. it looks like it does the job. if i were writing somethign to do the same job, i'd be storing the hostname output to a variable so i don't keep calling it i guess. in fact you could put the whole lot of echos and rap into ()'s and just redirect the whole output in one swoop at the end...

Code:
( echo 1
echo 2 
echo 3 ) > file.txt
additionally many of your echo's are redundant where you have two next to each other, just stick a \n in there instead of two seperate commands.

hm.. maybe i DO know what you mean...
 
Old 10-04-2006, 04:04 PM   #3
konsolebox
Senior Member
 
Registered: Oct 2005
Distribution: Gentoo, Slackware, LFS
Posts: 2,248
Blog Entries: 8

Rep: Reputation: 235Reputation: 235Reputation: 235
hello lorio. you can try this mod.

Code:
echo
echo "Please wait while creating" `hostname`".txt file..."
echo
{
	uname -a
	echo
	vmkmultipath -q
	echo "..................................................."
	mii-tool eth0
	echo "..................................................."
	vdf -h
	echo "..................................................."
	ls -l /vmfs
	echo "..................................................."
	echo "Swap"
	echo
	cat /proc/swaps
	echo "..................................................."
	echo "Registered VM's"
	echo
	vmware-cmd -l
	echo "..................................................."
	echo "VMware Licences : "
	echo
	cat /etc/vmware/license-2-0.esx.2.0
	echo
	echo "SMP :"
	echo
	cat /etc/vmware/license-2-2.esx-smp.2.0
	echo "..................................................."
} > `hostname`.txt
 
Old 10-10-2006, 07:23 AM   #4
lorio
LQ Newbie
 
Registered: Aug 2002
Location: CANADA
Distribution: Slackware
Posts: 10

Original Poster
Rep: Reputation: 0
konsolebox, thank you very much for your mod it worked perfectly. It's so easier that way! Thanks again!
 
Old 10-10-2006, 12:43 PM   #5
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985
but that was exactly what i suggested...
 
Old 10-10-2006, 12:49 PM   #6
lorio
LQ Newbie
 
Registered: Aug 2002
Location: CANADA
Distribution: Slackware
Posts: 10

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by acid_kewpie
but that was exactly what i suggested...
Sorry about that acid_kewpie , I didn't understand what you meant but when I saw the initial script modified (what konsolebox did) I realised what you meant. But you are using this : ( and ), and konsole box is using : { and }. Does both work in scripts?
 
Old 10-10-2006, 06:05 PM   #7
hlpboplz
Member
 
Registered: May 2005
Location: West Central Alabama
Distribution: Fedora Core 4
Posts: 34

Rep: Reputation: 15
Yea but...

Quote:
Originally Posted by acid_kewpie
but that was exactly what i suggested...
You didn't write it for him
 
  


Reply



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
How do you create shortcuts to "folders" and "binaries" in GNOME? ebenh Linux - Desktop 5 01-21-2008 05:28 AM
Samba: "homes" share, cannot create directories, can create files Herg Linux - Software 1 09-14-2006 08:48 AM
Microsoft Bluetooth mouse on suse9.2 "HID create error 25" mr-pear Linux - Hardware 0 08-16-2005 02:33 PM
"cannot exec `as': ..." AND "C compiler cannot create ..." pr3st0 Linux - Software 0 10-15-2004 12:42 PM
"ow to create and execute script" zameer_india Linux - Software 4 10-11-2004 11:25 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 12:06 AM.

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
Open Source Consulting | Domain Registration