Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Array of servers list to email

Status
Not open for further replies.

proggybilly

Programmer
Apr 30, 2008
110
US
Hey all,
I am writing a script that checks to see if my servers have backed up within a certain amount of days. I want to put the server name and number of days into an array for each server, for example @backup would look like:
Code:
server1 2
server2 2
server3 1

Then what I want to do is loop through the array and put the information into a single email so that the body looks similar to:
Code:
Server1 has not backed up in the last 2 day(s)
Server2 has not backed up in the last 2 day(s)
Server3 has not backed up in the last 1 day(s)

Any help is much appreciated. I am learning alot of perl, but I need to accomplish this before I actually learn what to do as I have a project that is moving faster than my study material.
 
It's not an array you want; they are indexed by cardinals, i.e. non-negative integers. You need a hash, %backup, which is indexed by strings.

Code:
[url=http://perldoc.perl.org/functions/my.html][black][b]my[/b][/black][/url] [blue]%backup[/blue] = [red]([/red]
    [purple]server1[/purple] => [fuchsia]2[/fuchsia],
    [purple]server2[/purple] => [fuchsia]2[/fuchsia],
    [purple]server3[/purple] => [fuchsia]1[/fuchsia],
[red])[/red][red];[/red]

[olive][b]foreach[/b][/olive] [black][b]my[/b][/black] [blue]$server[/blue] [red]([/red][url=http://perldoc.perl.org/functions/sort.html][black][b]sort[/b][/black][/url] [url=http://perldoc.perl.org/functions/keys.html][black][b]keys[/b][/black][/url] [blue]%backup[/blue][red])[/red] [red]{[/red]
    [url=http://perldoc.perl.org/functions/print.html][black][b]print[/b][/black][/url] [red]"[/red][purple][purple][b]\u[/b][/purple][blue]$server[/blue] has not backed up in the last [blue]$backup[/blue]{[blue]$server[/blue]} day(s)[purple][b]\n[/b][/purple][/purple][red]"[/red][red];[/red]
[red]}[/red]

Annihilannic.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top