LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Bash Script to increment (https://www.linuxquestions.org/questions/linux-newbie-8/bash-script-to-increment-4175437411/)

eyanu 11-16-2012 04:59 AM

Bash Script to increment
 
Am writing a script to automate VPS installations, however i need your help, my script should read the number of VPSs already there with:
Quote:

vzlist -a
This is supposed to return something like:
Quote:

CTID NPROC STATUS IP_ADDR HOSTNAME
104 42 running xx.xx.xx.xxx xxx.xxx.com
105 6 running 69.64.37.248 xxx.xxx.com
Running
Quote:

vzlist -a | wc -l
will return 3 including the heading CTID NPROC STATUS IP_ADDR HOSTNAME
I want a way to subtract the result of vzlist -a -1 so as to get the real number of machines running and then the script should also increment always by 1 during installations

druuna 11-16-2012 05:08 AM

Try this:
Code:

vzlist -a | awk 'END{ print NR-1 }'

eyanu 11-16-2012 05:10 AM

druuna, thanks alot....


All times are GMT -5. The time now is 05:07 AM.