LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices


Reply
  Search this Thread
Old 10-07-2022, 04:08 AM   #1
poonam2108
LQ Newbie
 
Registered: Oct 2022
Posts: 1

Rep: Reputation: 0
Question writing a script


hello all,
i need to take the output "df -h" from 200 servers having same password. any idea on how i can get it as i dont understand how to write the correct script.
 
Old 10-07-2022, 04:37 AM   #2
jmgibson1981
Senior Member
 
Registered: Jun 2015
Location: Tucson, AZ USA
Distribution: Debian
Posts: 1,151

Rep: Reputation: 393Reputation: 393Reputation: 393Reputation: 393
Homework? That are you got hired to do a job you don't have the knowledge for. We don't do homework here.

Maybe a for loop with the seq command?
 
Old 10-07-2022, 04:46 AM   #3
Turbocapitalist
LQ Guru
 
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 7,359
Blog Entries: 3

Rep: Reputation: 3767Reputation: 3767Reputation: 3767Reputation: 3767Reputation: 3767Reputation: 3767Reputation: 3767Reputation: 3767Reputation: 3767Reputation: 3767Reputation: 3767
Quote:
Originally Posted by poonam2108 View Post
... from 200 servers having same password.
First you ought to fix the arrangement there so that the passwords are not the same. Then take a look at using client SSH certificates (not just keys) for authentication. Then after that, look at basic shell scripting and loops using while or for. How are you going to identify the servers? Do you have a list of names or IP addresses? What have you tried so far?
 
Old 10-07-2022, 08:31 AM   #4
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 26,754

Rep: Reputation: 7983Reputation: 7983Reputation: 7983Reputation: 7983Reputation: 7983Reputation: 7983Reputation: 7983Reputation: 7983Reputation: 7983Reputation: 7983Reputation: 7983
Quote:
Originally Posted by poonam2108 View Post
hello all,
i need to take the output "df -h" from 200 servers having same password. any idea on how i can get it as i dont understand how to write the correct script.
Lots of ideas, and there are lots of ways to do this. So post what you've written/done/tried and tell us where you're stuck, and we'll be happy to help.
 
Old 10-07-2022, 02:42 PM   #5
elgrandeperro
Member
 
Registered: Apr 2021
Posts: 415
Blog Entries: 2

Rep: Reputation: Disabled
You would use expect. Expect is a simple scripting language that can "login" and execute things like you are typing. The syntax is pretty vague, but it is easy to debug.

Yes, if you used public key authentication or took the time to install any time of management/auditing tool this would be easy.

simple expect program:

https://www.digitalocean.com/communi...ample-tutorial

Never used pssh or mpssh they seem like reasonable for your case.

Last edited by elgrandeperro; 10-11-2022 at 08:13 PM.
 
Old 10-07-2022, 03:17 PM   #6
wpeckham
LQ Guru
 
Registered: Apr 2010
Location: Continental USA
Distribution: Debian, Ubuntu, RedHat, DSL, Puppy, CentOS, Knoppix, Mint-DE, Sparky, VSIDO, tinycore, Q4OS, Manjaro
Posts: 5,767

Rep: Reputation: 2765Reputation: 2765Reputation: 2765Reputation: 2765Reputation: 2765Reputation: 2765Reputation: 2765Reputation: 2765Reputation: 2765Reputation: 2765Reputation: 2765
I set up the config for mpssh to do such a thing. In my case every one of about 900 servers had different passwords, but I had pushed ssh keys out to them over several months time as part of an access and upgrade cycle.

There are better management tools available, and for the space information one might even leverage SNMP if it is available and configured on all nodes.

Why do you want to do this with a script?
 
1 members found this post helpful.
Old 10-10-2022, 09:48 PM   #7
rnturn
Senior Member
 
Registered: Jan 2003
Location: Illinois (SW Chicago 'burbs)
Distribution: openSUSE, Raspbian, Slackware. Previous: MacOS, Red Hat, Coherent, Consensys SVR4.2, Tru64, Solaris
Posts: 2,818

Rep: Reputation: 550Reputation: 550Reputation: 550Reputation: 550Reputation: 550Reputation: 550
Quote:
Originally Posted by poonam2108 View Post
hello all,
i need to take the output "df -h" from 200 servers having same password. any idea on how i can get it as i dont understand how to write the correct script.
Start with the basics:

How would you get the output of that command from a single server?

How would you go through a list of servers in a script? (Say if their hostnames or IP addresses were stored in a file.)

Then, once you can do those two things, how might you combine those two activities into a script to go through the list of servers and issue 'df -h' on each?

Small steps.

(Personally, I'd say that this is a job for Ansible. An inventory file with information for the 200 servers and a playbook that has a primary task that issues "df -h" should do the trick but... that's probably not within the scope of the assignment.)

HTH...
 
Old 10-10-2022, 10:58 PM   #8
wpeckham
LQ Guru
 
Registered: Apr 2010
Location: Continental USA
Distribution: Debian, Ubuntu, RedHat, DSL, Puppy, CentOS, Knoppix, Mint-DE, Sparky, VSIDO, tinycore, Q4OS, Manjaro
Posts: 5,767

Rep: Reputation: 2765Reputation: 2765Reputation: 2765Reputation: 2765Reputation: 2765Reputation: 2765Reputation: 2765Reputation: 2765Reputation: 2765Reputation: 2765Reputation: 2765
I would use a script for a small number of servers, perhaps a dozen. A utility like MPSSH for larger numbers, perhaps up to 50. For any arbitrary larger number of hosts something of a moniter application like NAGIOS or ZABBIX, or a manager like Ansible, will serve better and scale properly. They also give you additional reports, monitor reports over time to detect trends, and cover network connectivity and connection nodes if you set that up properly.

If your number of servers is large and potentially growing, there is no reason to use a quick-n-dirty solution that you will have to reinvent forever.
 
Old 10-11-2022, 03:28 PM   #9
sundialsvcs
LQ Guru
 
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 10,691
Blog Entries: 4

Rep: Reputation: 3947Reputation: 3947Reputation: 3947Reputation: 3947Reputation: 3947Reputation: 3947Reputation: 3947Reputation: 3947Reputation: 3947Reputation: 3947Reputation: 3947
@wpeckham brings up a very(!) important point: Unless this is just a 'homework problem,' the first question that you should ask yourself is ... "hasn't 'this' been done before?" Undoubtedly it has, no matter what "'this'" is.

Quote:
Actum Ne Agas: "Do Not Do A Thing Already Done."
In this grand "open-source world," a tremendous number of very-generous people have "already done" an amazing number of things ... sometimes having spent more than a year developing it ... and then they shared(!) it.

Of course it is "instinctive" to jump directly between "this is what I have to do" and "this is the first thing that comes to my mind as a way for me(!) to solve it." But, in the present day, you really need to break yourself of that "instinct."

Last edited by sundialsvcs; 10-11-2022 at 03:36 PM.
 
  


Reply



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
Writing Apps & Helpers for writers (all kinds) tech-writing, fiction, etc?? linus72 Debian 9 09-28-2009 09:34 AM
Writing to tty causes writing to disk? (in ancient 2.2.x kernel) borsburn Linux - Kernel 0 12-17-2008 12:47 PM
LXer: Democratization, Writing and Writing Code LXer Syndicated Linux News 0 11-22-2006 05:03 AM
Writing CD Writing Software starunj Linux - Software 1 12-28-2003 05:05 AM
cd writing software which supports multisession writing jayakrishnan Linux - General 3 03-24-2003 05:51 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Server

All times are GMT -5. The time now is 05:29 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
Open Source Consulting | Domain Registration