LinuxQuestions.org
Share your knowledge at the LQ Wiki.
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 11-16-2012, 05:59 AM   #1
eyanu
Member
 
Registered: Jul 2012
Location: kampala,Uganda
Distribution: backtrack
Posts: 87

Rep: Reputation: Disabled
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
 
Old 11-16-2012, 06:08 AM   #2
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387
Try this:
Code:
vzlist -a | awk 'END{ print NR-1 }'
 
1 members found this post helpful.
Old 11-16-2012, 06:10 AM   #3
eyanu
Member
 
Registered: Jul 2012
Location: kampala,Uganda
Distribution: backtrack
Posts: 87

Original Poster
Rep: Reputation: Disabled
druuna, thanks alot....
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
Increment in bash graphicsmanx1 Programming 18 11-23-2012 11:23 PM
Bash shell script: Str(007) to int(7),increment it(8) & convert back to string(008) drwatson_droid Programming 5 12-01-2011 11:44 AM
how to increment the date in a file name via bash script tensigh Programming 10 07-23-2010 04:49 AM
[Bash] increment number in a string czezz Programming 4 07-01-2009 12:34 PM
bash equivalent to C increment operator andrewb758 Linux - General 5 02-21-2009 01:25 PM


All times are GMT -5. The time now is 08:06 PM.

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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration