nixCraft Linux / UNIX / Shell Scripting Forum

nixCraft

Linux / UNIX 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 ...


Register free or login to your account to remove all advertisements.

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

Linux answers from nixCraft.


Shell scripting You can discuss the shell scripting, request shell scripts and scripting techniques

Reply

 

Thread Tools Display Modes
  #1 (permalink)  
Old 25th October 2007, 02:08 AM
Junior Member
 
Join Date: Sep 2007
OS: fedora 7
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Power: 0
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 25th October 2007, 03:21 AM
jesse's Avatar
Junior Member
 
Join Date: Aug 2007
OS: gentoo&debian
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Power: 0
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 25th October 2007, 11:22 AM
Junior Member
 
Join Date: Sep 2007
OS: fedora 7
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Power: 0
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 25th October 2007, 12:08 PM
nixcraft's Avatar
Never say die
 
Join Date: Jan 2005
Location: BIOS
OS: RHEL
Scripting language: Bash, Perl, Python
Posts: 3,294
Thanks: 13
Thanked 411 Times in 304 Posts
Rep Power: 10
nixcraft has a reputation beyond reputenixcraft has a reputation beyond reputenixcraft has a reputation beyond reputenixcraft has a reputation beyond reputenixcraft has a reputation beyond reputenixcraft has a reputation beyond reputenixcraft has a reputation beyond reputenixcraft has a reputation beyond reputenixcraft has a reputation beyond reputenixcraft has a reputation beyond reputenixcraft has a reputation beyond repute
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 Gite
Be proud RHEL user, and let the world know about your enterprise choices! Join RedHat user group.
Do you run a Linux? Let's face it, you need help!
Cricket & IPL News Blog
Reply With Quote
  #5 (permalink)  
Old 25th October 2007, 08:53 PM
Junior Member
 
Join Date: Sep 2007
OS: fedora 7
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Power: 0
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 29th October 2007, 11:17 PM
nixcraft's Avatar
Never say die
 
Join Date: Jan 2005
Location: BIOS
OS: RHEL
Scripting language: Bash, Perl, Python
Posts: 3,294
Thanks: 13
Thanked 411 Times in 304 Posts
Rep Power: 10
nixcraft has a reputation beyond reputenixcraft has a reputation beyond reputenixcraft has a reputation beyond reputenixcraft has a reputation beyond reputenixcraft has a reputation beyond reputenixcraft has a reputation beyond reputenixcraft has a reputation beyond reputenixcraft has a reputation beyond reputenixcraft has a reputation beyond reputenixcraft has a reputation beyond reputenixcraft has a reputation beyond repute
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 Gite
Be proud RHEL user, and let the world know about your enterprise choices! Join RedHat user group.
Do you run a Linux? Let's face it, you need help!
Cricket & IPL News Blog
Reply With Quote
  #7 (permalink)  
Old 30th October 2007, 02:17 PM
Junior Member
 
Join Date: Sep 2007
OS: fedora 7
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Power: 0
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 31st October 2007, 06:06 PM
nixcraft's Avatar
Never say die
 
Join Date: Jan 2005
Location: BIOS
OS: RHEL
Scripting language: Bash, Perl, Python
Posts: 3,294
Thanks: 13
Thanked 411 Times in 304 Posts
Rep Power: 10
nixcraft has a reputation beyond reputenixcraft has a reputation beyond reputenixcraft has a reputation beyond reputenixcraft has a reputation beyond reputenixcraft has a reputation beyond reputenixcraft has a reputation beyond reputenixcraft has a reputation beyond reputenixcraft has a reputation beyond reputenixcraft has a reputation beyond reputenixcraft has a reputation beyond reputenixcraft has a reputation beyond repute
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 Gite
Be proud RHEL user, and let the world know about your enterprise choices! Join RedHat user group.
Do you run a Linux? Let's face it, you need help!
Cricket & IPL News Blog
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 
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 Off


Similar Threads

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


All times are GMT +5.5. The time now is 08:50 AM.


Powered by vBulletin® Version 3.8.6 - Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.2
©2005-2010 nixCraft. All rights reserved

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 33 34 35 36 37 38 39 40