sysadmin

How can I automate running commands remotely over SSH to multiple servers in parallel?

限于喜欢 提交于 2019-11-28 16:44:33
I've searched around a bit for similar questions, but other than running one command or perhaps a few command with items such as: ssh user@host -t sudo su - However, what if I essentially need to run a script on (let's say) 15 servers at once. Is this doable in bash? In a perfect world I need to avoid installing applications if at all possible to pull this off. For argument's sake, let's just say that I need to do the following across 10 hosts: Deploy a new Tomcat container Deploy an application in the container, and configure it Configure an Apache vhost Reload Apache I have a script that

lsof survival guide [closed]

夙愿已清 提交于 2019-11-28 14:56:43
lsof is an increadibly powerful command-line utility for unix systems. It lists open files, displaying information about them. And since most everything is a file on unix systems, lsof can give sysadmins a ton of useful diagnostic data. What are some of the most common and useful ways of using lsof, and which command-line switches are used for that? To show all networking related to a given port : lsof -iTCP -i :port lsof -i :22 To show connections to a specific host, use @host lsof -i@192.168.1.5 Show connections based on the host and the port using @host:port lsof -i@192.168.1.5:22 grep ping

How do I add a user in Ubuntu? [closed]

纵饮孤独 提交于 2019-11-28 14:35:42
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 7 years ago . Specifically, what commands do I run from the terminal? 回答1: Without a home directory sudo useradd myuser With home directory sudo useradd -m myuser Then set the password sudo passwd myuser Then set the shell sudo usermod -s /bin/bash myuser 回答2: Here's the command I almost always use (adding user kevin):

How to export a variable in bash

被刻印的时光 ゝ 提交于 2019-11-28 12:07:13
I need to set a system environment variable from a bash script that would be available outside of the current scope. So you would normally export environment variables like this: export MY_VAR=/opt/my_var But I need the environment variable to be available at a system level though. Is this possible? Jeremy Cantrell This is the only way I know to do what you want: In foo.sh, you have: #!/bin/bash echo MYVAR=abc123 And when you want to get the value of the variable, you have to do the following: $ eval "$(foo.sh)" # assuming foo.sh is in your $PATH $ echo $MYVAR #==> abc123 Depending on what you

Renaming lots of files in Linux according to a pattern [closed]

心已入冬 提交于 2019-11-28 09:10:34
I'm trying to do three things with the mv command, but not sure it's possible? Probably need a script. not sure how to write it. All files are in same folder. 1) Files ending with v9.zip should just be .zip (the v9 removed) 2) Files containing _ should be - 3) Files with Uppercase letter next to a lowercase letter (or lowercase next to an Uppercase) should have a space between them. So MoveOverNow would be Move Over Now and ruNaway would be ruN away [A-Z][a-z] or [a-z][A-Z] becomes [A-Z] [a-z] and [a-z] [A-Z] My favorite solution is my own rename script . The simplest example that maps to your

Proper way to run a script using cron?

半城伤御伤魂 提交于 2019-11-28 05:21:40
问题 When running a script with cron, any executable called inside must have the full path. I discovered this trying to run wondershaper, when many errors showed when it tried to call tc. So my question is, what's the proper way to overcome this problem? Possible solutions: cd to the executable folder and prepare symbolic links to any other called executable there (not sure if it works - low portability) use full paths in the script (it works - low portability across different distros) exporting a

Monitor a set of files for changes and execute a command on them when they do

痞子三分冷 提交于 2019-11-28 01:31:54
问题 The (command line) interface I have in mind is like so: watching FILE+ do COMMAND [ARGS] (and COMMAND [ARGS])* Where any occurrence of " {} " in COMMAND is replaced with the name of the file that changed. And note that " do " and " and " are keywords. For example: > watching foo.txt bar.txt do scp {} somewhere.com:. and echo moved {} to somewhere Or: > watching foo.c do gcc foo.c and ./a.out I'm not wedded to that interface though. I'll add my script that does that as an answer and see if

How to find out what group a given user has?

巧了我就是萌 提交于 2019-11-27 17:00:17
In Unix/Linux, how do you find out what group a given user is in via command line? groups or groups user This one shows the user's uid as well as all the groups (with their gids) they belong to id userid On Linux/OS X/Unix to display the groups to which you (or the optionally specified user) belong, use: id -Gn [user] which is equivalent to groups [user] utility which has been obsoleted on Unix. On OS X/Unix, the command id -p [user] is suggested for normal interactive. Explanation on the parameters: -G , --groups - print all group IDs -n , --name - print a name instead of a number, for -ugG

Python script to list users and groups

别说谁变了你拦得住时间么 提交于 2019-11-27 14:37:06
I'm attempting to code a script that outputs each user and their group on their own line like so: user1 group1 user2 group1 user3 group2 ... user10 group6 etc. I'm writing up a script in python for this but was wondering how SO might do this. p.s. Take a whack at it in any language but I'd prefer python. EDIT: I'm working on Linux. Ubuntu 8.10 or CentOS =) S.Lott For *nix, you have the pwd and grp modules. You iterate through pwd.getpwall() to get all users. You look up their group names with grp.getgrgid(gid) . import pwd, grp for p in pwd.getpwall(): print p[0], grp.getgrgid(p[3])[0] the grp

What are the limitations of the flask built-in web server

时间秒杀一切 提交于 2019-11-27 11:28:05
I'm a newbie in web server administration. I've read multiple times that flask built-in web server is not designed for "production", and must be used only for tests and debug... But what if my app touchs only a thousand users who occasionnaly send data to the server ? If it works, when will I have to bother with the configuration of a more sophisticated web server ? (I am looking for approximative metrics). In a nutshell, I would love to find what the builtin web server can do (with approx thresholds) and what it cannot. Thanks a lot ! There isn't one right answer to this question, but here