LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   How to create a Create script "easier"? (https://www.linuxquestions.org/questions/linux-newbie-8/how-to-create-a-create-script-easier-489463/)

lorio 10-04-2006 02:43 PM

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


acid_kewpie 10-04-2006 02:48 PM

easier?? :confused: 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...

konsolebox 10-04-2006 04:04 PM

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


lorio 10-10-2006 07:23 AM

konsolebox, thank you very much for your mod it worked perfectly. It's so easier that way! Thanks again!

acid_kewpie 10-10-2006 12:43 PM

but that was exactly what i suggested... :confused:

lorio 10-10-2006 12:49 PM

Quote:

Originally Posted by acid_kewpie
but that was exactly what i suggested... :confused:

Sorry about that acid_kewpie :o , 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?

hlpboplz 10-10-2006 06:05 PM

Yea but...
 
Quote:

Originally Posted by acid_kewpie
but that was exactly what i suggested... :confused:

You didn't write it for him:tisk: ;)


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