nixCraft Linux Forum

nixCraft

Linux Tech Support Forum

bash script to collect info

This is a discussion on bash script to collect info within the Shell scripting forums, part of the Development/Scripting category; hi i need script that will ssh to some Linux red hat via ssh and collect configuration file (rpm list ...


Go Back   nixCraft Linux Forum > Development/Scripting > Shell scripting

Register FAQ Members List Calendar Mark Forums Read

Reply

 

LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 10-25-2007, 02:08 AM
Junior Member
User
 
Join Date: Sep 2007
Posts: 5
adahan is on a distinguished road
Default bash script to collect info

hi i need script that will ssh to some Linux red hat via ssh and collect configuration file (rpm list and /etc/hosts etc..)

I read about the ssh and there is some problem to save the password in the script for this moment i don't care about that,

thanks
moshik
Reply With Quote

  #2 (permalink)  
Old 10-25-2007, 03:21 AM
jesse's Avatar
Junior Member
User
 
Join Date: Aug 2007
Posts: 12
jesse is on a distinguished road
Default

That's quite easy to achieve (with pubkeys so you don't have to enter passwords everytime). Run Remote Commands with SSH should get you started. However, there are much better tools for monitoring multiple boxes out there. Zabbix, Munin, Monit and Nagios are just the ones coming to mind right now.
__________________
teh.geekosphere.org
Reply With Quote
  #3 (permalink)  
Old 10-25-2007, 11:22 AM
Junior Member
User
 
Join Date: Sep 2007
Posts: 5
adahan is on a distinguished road
Default

thanks for the quick response,but i can't use those program only with bash script,
so. if you can supply some script that will collect information from Linux and then will move the information to other Linux via (scp, or rsync or sftp)
Reply With Quote
  #4 (permalink)  
Old 10-25-2007, 12:08 PM
nixcraft's Avatar
Never say die
User
 
Join Date: Jan 2005
Location: BIOS
Posts: 727
nixcraft is an unknown quantity at this point
Default

Simple sample script:

Code:
#!/bin/bash
OUT=report.out.txt
>$OUT
echo "Hostname : $(hostname)" >> $OUT
echo "Date : $(date)" >> $OUT
echo "Memory info: " >> $OUT
free -m >>$OUT
echo "Disk info: " >> $OUT
df -h >>$OUT
scp $OUT you@somewhere.com
# mail -s "Sys Info" you@somewherelese.com < $OUT
Now write and modify script as above.
__________________
Vivek | My personal blog
Linux Evangelist
Play hard stay cool
Reply With Quote
  #5 (permalink)  
Old 10-25-2007, 08:53 PM
Junior Member
User
 
Join Date: Sep 2007
Posts: 5
adahan is on a distinguished road
Default

thanks

now i need to move some file to folder i use this :

#!/bin/bash
OUT="$(hostname)"
mkdir "$(hostname)"
`cp /etc/hosts` >> OUT
#free -m >>$OUT
#echo "Disk info: " >> $OUT
#df -h >>$OUT
#scp $OUT you@somewhere.com

and it not move please assist
Reply With Quote
  #6 (permalink)  
Old 10-29-2007, 11:17 PM
nixcraft's Avatar
Never say die
User
 
Join Date: Jan 2005
Location: BIOS
Posts: 727
nixcraft is an unknown quantity at this point
Default

To copy files to folder
Code:
cp /path/to/file /path/to/folder
NO need to use `cmd` or $(cmd) statement as script can execute cp directly
__________________
Vivek | My personal blog
Linux Evangelist
Play hard stay cool
Reply With Quote
  #7 (permalink)  
Old 10-30-2007, 02:17 PM
Junior Member
User
 
Join Date: Sep 2007
Posts: 5
adahan is on a distinguished road
Default

thanks,

how i can set in the script telnet session

telnet to ip address
password
run command and execute to file/folder

and
i want to make cp to file's from some folders to backup folder in one line

cp /path/to/file and /path/to/file and path/to/file and then move to /path/to/folder

BR,
moshik
Reply With Quote
  #8 (permalink)  
Old 10-31-2007, 06:06 PM
nixcraft's Avatar
Never say die
User
 
Join Date: Jan 2005
Location: BIOS
Posts: 727
nixcraft is an unknown quantity at this point
Default

Don't use telnet, it is insecure protocol. Use openssh server and open ssh client.

First set ssh keys, see my howto:
SSH Public key based authentication - Howto

Once done that, run ssh command as follows
Code:
ssh you@server-name.com command1
ssh you@server-name.com cp /path/to/something /here/dest
__________________
Vivek | My personal blog
Linux Evangelist
Play hard stay cool
Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads

Thread Thread Starter Forum Replies Last Post
howto get my cpu info on linux system? chiku Linux software 3 05-08-2008 01:16 AM
Does Redhat have "what" utility which can be used to display identification Info? DCAO Linux software 2 10-30-2007 07:23 PM
Require Shell Script Which sends all server info on mail puppen Linux software 3 10-25-2006 08:07 PM
USER INFO asim.mcp Linux software 1 08-09-2006 03:18 AM
find out info. reg. files for each user in the system ganes Solaris/OpenSolaris 6 09-20-2005 06:49 PM


All times are GMT +5.5. The time now is 04:40 PM.


Powered by vBulletin® Version 3.7.0 - Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO 3.1.0

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32