A form of computer programming that — in the context of system administration — lends it self well to automating tasks.

learn more… | top users | synonyms (2)

217
votes
11answers
252k views

How to determine if a bash variable is empty?

What is the best way to determine if a variable in bash contains ""? I have heard it recommended that I do if [ "x$variable" = "x" ] Is that the correct way? (there must be something more ...
116
votes
3answers
41k views

What is the difference between double and single square brackets in bash?

I just wondered what exactly the difference between [[ $STRING != foo ]] and [ $STRING != foo ] is, apart from that the latter is posix-compliant, found in sh and the former is an extension ...
82
votes
8answers
139k views

Run a .bat file in a scheduled task without a window

I have a scheduled task that starts a batch script that runs robocopy every hour. Every time it runs a window pops up on the desktop with robocopy's output, which I don't really want to see. I ...
49
votes
6answers
12k views

Why use Chef/Puppet over shell scripts?

New to Puppet and Chef tools. Seems like the job that they are doing can be done with shell scripting. Maybe it was done in shell scripts until these came along. I would agree they are more readable. ...
33
votes
8answers
5k views

How can I run arbitrarily complex command using sudo over ssh?

I have a system that I can only log in to under my username (myuser), but I need to run commands as other user (scriptuser). So far, I have come up with the following to run the commands I need: ssh ...
29
votes
8answers
25k views

How to make bash scripts print out every command before it executes?

For example, I have a simple bash file #!/bin/bash cd ~/hello ls How can I make it display every command before executing it? Just the opposite effect of "@echo off" in windows batch scripting.
28
votes
5answers
2k views

How can a Linux Administrator improve their shell scripting and automation skills?

In my organization, I work with a group of NOC staff, budding junior engineers and a handful of senior engineers; all with a focus on Linux. One interesting step in the way the company grows talent is ...
26
votes
13answers
1k views

How to encourage Windows administrators to pick up scripting?

When I worked as an administrator in my first job, I was frustrated that our administration processes with Windows servers were a series of point-and-clicks; we could never match the level of ...
25
votes
14answers
11k views

How do I find out what version of Linux is running?

Sometimes your scripts need to behave differently on different Linux's. How can I determine which version of Linux a script is running on?
19
votes
5answers
16k views

What is “-bash: !”: event not found"

Try executing the following under a bash shell echo "Reboot your instance!" On my installation: root@domU-12-31-39-04-11-83:/usr/local/bin# bash --version GNU bash, version 4.1.5(1)-release ...
19
votes
5answers
11k views

Scripted install of MySQL on Ubuntu

I need to write a script that will build my server from a fresh Ubuntu server install. Among things like Apache and PHP it needs to install MySQL. The only problem here is that when I install MySQL ...
19
votes
8answers
964 views

How do I become a scripting guy?

I am a fairly new Windows Systems Administrator. I have done some basic batch files and some other scripting. I would like to know what path I should take to become a better scripter. What language ...
18
votes
8answers
7k views

Is there any reason to use bash over zsh?

I'm curious about why one would want to run bash instead of zsh. I mean zsh is fully backwards-compatible with bash. Don't get me wrong: I don't dislike bash or anything. I just genuinely want to ...
17
votes
7answers
17k views

How do I run a local bash script on remote machines via ssh?

I am looking for a way to push configuration from one central machine to several remote machines without the need to install anything on the remote machines. The aim is to do something like you ...
16
votes
4answers
14k views

How to automatically run a script when the contents of a directory changes in Linux?

I want to automatically run a script whenever new files are copied into a particular directory. In other words, is there a way in Linux to "watch" a directory for changes and then run something in ...
14
votes
6answers
42k views

Run a shell script as a different user

What's a good way of running a shell script as a different user. I'm using Debian etch, and I know which user I want to impersonate. If I was doing it manually, I would do: su postgres ...
14
votes
4answers
11k views

Bash Scripting: Require script to be run as root (or with sudo)

I'm trying to write a bash script (in Ubuntu) that will backup a directory using tar. How can I do a check in the script so that it can only be run as root (or with sudo)? For instance, if a user ...
14
votes
4answers
3k views

In CentOS 4.4, how can I strip escape sequences from a text file?

What command can I use to strip color-code escape sequences from a text file? Ideally something I can pipe through. If I have a file with a bunch of coloured text rainbow.txt, what goes in the gap: ...
14
votes
2answers
81k views

Using ICACLS to set permissions on user directories

I'm trying to reset permissions on user directories and having a bit of trouble with the last step of my script. My script basically takes ownership of the entire user directory, resets the ...
13
votes
5answers
61k views

Need to add a “Wait” command to a Powershell script

Here is my current code: Write-output “ENTER THE FOLLOWING DETAILS - When Creating Multiple New Accounts Go to EMC hit F5(refresh) and make sure previous new account is listed before ...
13
votes
2answers
6k views

Passing default answers to apt-get package install questions?

I'm trying to write a configuration script for new servers, and one of the first steps is to install a series of required packages, such as MySQL, phpMyAdmin, etc. using apt-get install However, when ...
13
votes
4answers
13k views

Where is a good permanent place to install custom bash scripts?

I'm about to install "leiningen" which is a bash script for the clojure programming language with a lot of usefulness... ...but I'm not sure where it is appropriate to -put- a executable script in ...
12
votes
2answers
304 views

What is the industry standard method for administering the change of the local administrator password for all machines on a domain?

Although there appears to be three available options, one of which is actually secure, there seems to be only two available choices that will be able to impact machines that are not powered on at the ...
11
votes
4answers
16k views

How to run script via SSH that doesn't end when I close connection?

I need to run script, that takes long time to execute, or I just want it to run forever. I can't just SSH to my machine, because when I disconnect it stops running. Is there any way to run script ...
11
votes
2answers
7k views

What is needed for a linux service to be supported by chkconfig?

I am trying to add to the auto start at boottime a linux service through the chkconfig -add <servicename> and I get a message saying service <servicename> does not support chkconfig ...
11
votes
5answers
18k views

How can I check the build status of a Jenkins build from the command line?

In trying to make doing the right thing easy, I'm looking for and making command line tools for our developers. I'm hoping to find a way that I can check the jenkins build status without switching to ...
11
votes
3answers
12k views

How to configure postfix to pipe all incoming email to a script?

Using postfix, I'd like all incoming mail, to any address (including those that don't map to local users) to be piped to a script. I've tried configuring mailbox_command in /etc/postfix/main.cf: ...
11
votes
7answers
3k views

How did you implement log management on your servers?

I'm trying to figure out how other people implement their log management systems. I have 20-30 Linux servers and a few Windows boxes (most of them virtualized). We utilize a lot of Perl and Bash ...
10
votes
5answers
2k views

Where do you normally keep your UNIX/Linux scripts?

There are numerous scripts that I have written for my server. Some of them are in my ~/scripts and some of them are in application directories. I am just wondering is there a directory that you would ...
10
votes
5answers
1k views

Sort a list of domain names (FQDNs) starting from tld and working left

I am looking to sort a list of domain names (a web filter whitelist) starting from the TLD and working upwards. I am looking any *nix or windows tools that can do this easily, though a script would ...
10
votes
4answers
17k views

How to add a script to startup and shutdown in debian?

the title pretty much sums it up. how do I add a startup.sh and shutdown.sh of my server app to the startup and shutdown sequence of the Debian OS?
10
votes
7answers
23k views

Tool to test a user account and password (test login)

Yeah, I can fire up a VM or remote into something and try the password...I know...but is there a tool or script that will simulate a login just enough to confirm or deny that the password is correct? ...
10
votes
5answers
9k views

Using mysqldump in cron job without root password

If I login with the root password on my box I can simply type mysqldump --all-databases and I will get th expected "Dump". I setup a job in cron.daily to run and dump this to a backup drive. The ...
10
votes
3answers
1k views

Deploying Printers via GPO/GPP - is there a programmatic option?

For reasons beyond my control, I've been tasked with setting up GPO/GPPs to deploy our 100+ printers to our 1000+ clients. The good news is that we have over a dozen sites, and for the most part, I'm ...
10
votes
3answers
951 views

Temporarlly increasing sudo's timeout for the duration of an install script

I'm trying to write a script, that will install a bunch of software, I'd like to not have to run everything as root, so I'd like to be able to prompt for a password and then go about the install, ...
9
votes
6answers
4k views

Setting the Timezone with an automated script

I'm writing scripts to automate setting up new slicehost installations. In a perfect world, after I started the script, it would just run, with no attention from me. I have succeeded, with one ...
8
votes
9answers
7k views

Batch Query Dell Service Tags

Anyone know of a way to get a bunch of information for a list of service tags, does Dell have a section on their site for this? I would also be open to any Perl / Python libraries or *nix shell ...
8
votes
7answers
20k views

Need leading zero for batch script using %time% variable

I came across a bug in my DOS script that uses date and time data for file naming. The problem was I ended up with a gap because the time variable didn't automatically provide leading zero for hour ...
8
votes
6answers
3k views

What does passing the -xe parameters to /bin/bash do

Exactly what the title says. I'm not having much luck finding the proper documentation to see what -xe does in the following use case: #!/bin/bash -xe what do those parameters do and where it is ...
8
votes
1answer
3k views

EC2 Startup - How to Tell When Windows Ready?

I am working with Amazon EC2, and I have some Windows AMIs backed with EBS. When I launch a new instance from an EBS snapshot, the EC2Config service prepares the Windows machine for me. I know when ...
8
votes
1answer
8k views

How to start tomcat in remote debug mode under Ubuntu 10?

I'm getting crazy to set up Tomcat in remote debug mode under ubuntu 10. Basically I added this to /etc/init.d/tomcat6 (at the beginning): JAVA_OPTS="-Djava.awt.headless=true -Xmx256M -Xdebug ...
8
votes
4answers
6k views

Fast extraction of a time range from syslog logfile?

I've got a logfile in the standard syslog format. It looks like this, except with hundreds of lines per second: Jan 11 07:48:46 blahblahblah... Jan 11 07:49:00 blahblahblah... Jan 11 07:50:13 ...
8
votes
2answers
688 views

Using Diskpart in a PowerShell script won't allow script to reuse drive letter

I built a script that mounts (attach) a VHD using Diskpart, cleans out some system files and then unmounts (detach) it. It uses a foreach loop and is suppose to clean multiple VHD using the same ...
8
votes
2answers
9k views

Getting shell script to run as a daemon on CentOS?

EDIT: For some reason half of my post got truncated, not sure what happened. I will update soon and will post that it is updated here at the top. EDIT: I have updated the post again, sorry for the ...
7
votes
5answers
9k views

What command prints a string as “big ascii text art” in bash?

I'm looking for a program that turns an ASCII string into something like the "ascii art" below: .-"^`\ /`^"-. .' ___\ ...
7
votes
4answers
23k views

How can i fully log all bash scripts actions?

I want to capture ALL the logs data, both with error messages, from my script output, and redirect them all to log file. I have script like below: #!/bin/bash ( echo " `date` : part 1 - start " ssh ...
7
votes
3answers
3k views

echo based on grep result

I need a one liner which displays 'yes' or 'no' whether grep finds any results. I have played with grep -c, but without success.
7
votes
3answers
3k views

Bash script to count number of files

I have a script and I want to display different messages if a file exists or not. I have a script like: count=ls /import/*.zip | wc -l echo "Number of files: " $count if [ "$count" > "0" ]; then ...
7
votes
4answers
2k views

Vim - Trigger action\script on save\write?

This might be better for super user, but I figure as a tool of the trade it might be a better topic for here. I find often when editing in vim that I exit out, run some script that I am testing, and ...
7
votes
3answers
684 views

Delete a windows group in Active Directory

I am doing a cleanup of some AD groups that are no longer used. One of the AD groups I could not delete because it seems that a member has this group set as the primary group (which I assume someone ...