sysadmin

Run a linux system command as a superuser, using a python script

為{幸葍}努か 提交于 2019-11-27 10:57:10
问题 I have got postfix installed on my machine and I am updating virtual_alias on the fly programmatically(using python)(on some action). Once I update the entry in the /etc/postfix/virtual_alias, I am running the command: sudo /usr/sbin/postmap /etc/postfix/virtual_alias 2>>/work/postfix_valias_errorfile But I am getting the error: sudo: sorry, you must have a tty to run sudo I want to run the mentioned sudo command in a non-human way(meaning, I am running this system command from a python

Best practice to run Linux service as a different user

元气小坏坏 提交于 2019-11-27 09:59:20
Services default to starting as root at boot time on my RHEL box. If I recall correctly, the same is true for other Linux distros which use the init scripts in /etc/init.d . What do you think is the best way to instead have the processes run as a (static) user of my choosing? The only method I'd arrived at was to use something like: su my_user -c 'daemon my_cmd &>/dev/null &' But this seems a bit untidy... Is there some bit of magic tucked away that provides an easy mechanism to automatically start services as other, non-root users? EDIT: I should have said that the processes I'm starting in

lsof survival guide [closed]

血红的双手。 提交于 2019-11-27 08:56:17
问题 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 5 years ago . 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

How to export a variable in bash

馋奶兔 提交于 2019-11-27 06:52:10
问题 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? 回答1: 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 "$

How do I daemonize an arbitrary script in unix?

女生的网名这么多〃 提交于 2019-11-27 05:48:17
I'd like a daemonizer that can turn an arbitrary, generic script or command into a daemon . There are two common cases I'd like to deal with: I have a script that should run forever. If it ever dies (or on reboot), restart it. Don't let there ever be two copies running at once (detect if a copy is already running and don't launch it in that case). I have a simple script or command line command that I'd like to keep executing repeatedly forever (with a short pause between runs). Again, don't allow two copies of the script to ever be running at once. Of course it's trivial to write a "while(true

Best practice to run Linux service as a different user

落花浮王杯 提交于 2019-11-27 04:09:45
问题 Services default to starting as root at boot time on my RHEL box. If I recall correctly, the same is true for other Linux distros which use the init scripts in /etc/init.d . What do you think is the best way to instead have the processes run as a (static) user of my choosing? The only method I'd arrived at was to use something like: su my_user -c 'daemon my_cmd &>/dev/null &' But this seems a bit untidy... Is there some bit of magic tucked away that provides an easy mechanism to automatically

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

℡╲_俬逩灬. 提交于 2019-11-27 02:42:34
问题 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 5 years ago . 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

How to find out what group a given user has?

强颜欢笑 提交于 2019-11-26 23:51:27
问题 In Unix/Linux, how do you find out what group a given user is in via command line? 回答1: groups or groups user 回答2: This one shows the user's uid as well as all the groups (with their gids) they belong to id userid 回答3: 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.

Python script to list users and groups

眉间皱痕 提交于 2019-11-26 22:24:21
问题 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 =) 回答1: 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

Tracking CPU and Memory usage per process

久未见 提交于 2019-11-26 21:23:29
I suspect that one of my applications eats more CPU cycles than I want it to. The problem is - it happens in bursts, and just looking at the task manager doesn't help me as it shows immediate usage only. Is there a way (on Windows) to track the history of CPU & Memory usage for some process. E.g. I will start tracking "firefox", and after an hour or so will see a graph of its CPU & memory usage during that hour. I'm looking for either a ready-made tool or a programmatic way to achieve this. Martin08 Just type perfmon into Start > Run and press enter. When the Performance window is open, click