Create a Date Check Script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Create a Date Check Script
# 1  
Old 08-06-2013
Linux Create a Date Check Script

I have about 100 Linux servers running in Amazon EC2 (CentOS 6 based) and I need to run a 'date' command against all of them. Rather than logging into each individual server via 'ssh' and running the 'date' command, can someone please help me with how something like this can be scripted? I obviously have NO scripting experience what so ever sadly. I'd love to learn and become a stronger / more efficient Linux administrator but not sure where to start. Can anyone please give me any info on where to start, what I should start writing this script in (i.e. perl, python, bash, etc etc etc), and or anything else?

Thank you for your help!
# 2  
Old 08-06-2013
You still will need to log into every single server, but you can do it in a loop in a script. Set the servers up for passwordless login (--> man ssh), put their names into a file, and in a while loop read the server names line by line, issue the ssh user@hostname command, and collect the output into a log file.
# 3  
Old 08-06-2013
To access every server, I simply do:

Code:
ssh -i sshkey.pem user@server1/2/3/4/5/6/100

No password needed...
# 4  
Old 08-06-2013
if servers run time service (traditional port 13) you can do something like this:

Code:
 
{ print -u3 "\n"; cat <&3; } 3</dev/tcp/198.168.1.2/13
Tue Aug  6 13:03:40 2013

so put your IPs in one file and feed it into this one-liner
# 5  
Old 08-06-2013
So I have a list of hostnames:

Code:
server1.domain.tld - server100.domain.tld

Can you explain what you mean by "put my IP's in one file"? I don't see in your example where you call a file expected to be loaded with IP's or FQDN's...
# 6  
Old 08-06-2013
I put list of ip addresses into file called ip_list

Code:
 
cat ip_list
192.168.1.103
192.168.1.104
192.168.2.122

then run:

Code:
 
for ip in $( cat ip_list ); do 
        #echo $ip; 
        { print -u3 "\n"; cat <&3; } 3</dev/tcp/${ip}/13;
done

I have it working under ksh and I believe bash should work, too.
# 7  
Old 08-06-2013
how about this ideal?

Confirm if SNMP port is opened by default on these 100 cloud servers or not, then install MRTG (MRTG - Tobi Oetiker's MRTG - The Multi Router Traffic Grapher) or others monitoring tools, display their CPU/load information, which will show the date/time as well, it didn't show the exact time, but will give you reference.

second, confirm NTP service are set correctly, then you needn't worry about the time difference any more.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Please help, need to create script to remove lines by date in file

Please Help (novice to PERL and SHELL scripting)…. Need to create a script which removes all lines in $filename = "cycle_calendar_ftp_out" older than current date – a variable which will be a number of days passed to script. For Ex it will look at the end date which is the last field (4) and... (2 Replies)
Discussion started by: m3pwr
2 Replies

2. UNIX for Dummies Questions & Answers

Help in script to check file name with todays date

I am trying to include a snippet in my script to check if the file created is having today's date. eg: File name is : ABC.YYYYMMDD-nnn.log The script should check if 'YYYYMMDD' in the above file name matches with today's date. Can you please help me in achieving this. Thanks in advance!! (5 Replies)
Discussion started by: kiran1112
5 Replies

3. UNIX for Dummies Questions & Answers

Date check script (noob)

Hello, I've been given the task of checking the date of expiration dates and notify when the date is 30 days away from expiration. As stated in the Title, I'm very new to this, I did a good bit of work over the last two days to only find out I was going down the wrong path. I'm not... (3 Replies)
Discussion started by: drey4184
3 Replies

4. Shell Programming and Scripting

Please help I want script to check filename, size and date in specify path.

Please help, I want script to check filename, size and date in specify path. I want output as: DATE: YYYYMMDD HH:MM ------------------------------------------------ fileA,filesize,yyyy mm dd HH:MM fileA,filesize,yyyy mm dd HH:MM fileA,filesize,yyyy mm dd HH:MM fileA,filesize,yyyy mm dd... (1 Reply)
Discussion started by: akeji
1 Replies

5. Shell Programming and Scripting

help to create script for added date to list users

hi my friends im asking for the possibility to creat a script in ubuntu for added date to list users for doing this : - search in debug connected user of all connected users - if a new user is connect for the first time to my server the script record the date of the connection and added it... (1 Reply)
Discussion started by: amzioujda
1 Replies

6. Shell Programming and Scripting

Script to check file with previous date

Hi all,I need your help to create the script.I need a script to check the ZIP file at network location with yesterday date name. ZIP file creation date is current date, but name of the zip file is previous date. for example file name "20110216.zip" created today 201102017.I just want to return the... (1 Reply)
Discussion started by: deepaksingla
1 Replies

7. Shell Programming and Scripting

Perl Script to check file date and size

Hi guys, i am new to perl. I started reading the perl documents and try to come up with some logic. I am trying to create a script that would go into a location, search for todays files, then searches for all .txt files from today. If todays not found, its an error If file size is less... (26 Replies)
Discussion started by: DallasT
26 Replies

8. Shell Programming and Scripting

Create a script using DATE command?

Not even sure how to word this. Basically, we have a log file that gathers all alerts for a system. What I am doing is grepping through this file and grabbing certain strings that are outputted to a file, then mailed to a group. Here is the catch. Since I cannot copy this file to a temp file... (1 Reply)
Discussion started by: thecoffeeguy
1 Replies

9. Shell Programming and Scripting

Need help to create a date script

So I need to create a shell script that can take as input a numeric day, month and year and output the day of the week for the input date. So let's say, I input "programname 19 10 2006" it should output Thursday... I tried messing around with the grep and awk commands, but I can't get it to... (6 Replies)
Discussion started by: mredwardlee
6 Replies

10. UNIX for Dummies Questions & Answers

file date check script

I am creating a KSH script and need to check the filedate against the system date. I can get the sys date w. date command, and I was able to get the filedate w. the awk command but when I compare them w. an if condition statement I get syntax error. Not sure what's wrong, and other suggestions on... (4 Replies)
Discussion started by: jaxconsultant
4 Replies
Login or Register to Ask a Question