Questions tagged [scripting]
A form of computer programming that — in the context of system administration — lends it self well to automating tasks.
1,835
questions
1014
votes
15
answers
1.4m
views
How to determine if a bash variable is empty?
What is the best way to determine if a variable in bash is empty ("")?
I have heard that it is recommended that I do if [ "x$variable" = "x" ]
Is that the correct way? (there must be something more ...
547
votes
5
answers
275k
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 found in ...
190
votes
10
answers
317k
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 (i686-pc-...
174
votes
11
answers
352k
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 ...
102
votes
8
answers
131k
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.
99
votes
9
answers
428k
views
How can I fully log all bash scripts actions?
From my script output I want to capture ALL the logs data with error messages and redirect them all to log file.
I have script like below:
#!/bin/bash
(
echo " `date` : part 1 - start "
ssh -f ...
85
votes
6
answers
48k
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 ...
83
votes
12
answers
69k
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 -...
83
votes
7
answers
34k
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. ...
62
votes
9
answers
208k
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?
...
59
votes
8
answers
270k
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
./backup_db....
57
votes
9
answers
95k
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 ...
54
votes
5
answers
314k
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 ...
54
votes
10
answers
234k
views
How do I check the build status of a Jenkins build from the command line?
How do I check the Jenkins build status without switching to the browser?
If required, I can create a script using the JSON API, but I was wondering if there is already something like this built in.
44
votes
4
answers
71k
views
How to output a list of changed files from rsync?
I am using rsync in a bash script to keep files in sync between a few servers and a NAS. One issue I have run into is trying to generate a list of the files that have changed from the during the rsync....
44
votes
7
answers
57k
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 ...
42
votes
3
answers
38k
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 ...
41
votes
10
answers
114k
views
How do I read multiple lines from STDIN into a variable?
I've been googling this question to no avail. I'm automating a build process here at work, and all I'm trying to do is get version numbers and a tiny description of the build which may be multi-line. ...
40
votes
6
answers
65k
views
What command prints a string as "big ascii text art" in bash? [closed]
I'm looking for a program that turns an ASCII string into something like the "ascii art" below:
.-"^`\ /`^"-.
.' ___\ ...
38
votes
3
answers
333k
views
For Loop counting from 1 to n in a windows bat script
I need to run a windows command n times within a bat script file. I know how to do this in various programming languages but cannot manage to get it right on the windows command line :-(
I would ...
38
votes
4
answers
78k
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
...
37
votes
9
answers
117k
views
Multi-select menu in bash script [closed]
I'm a bash newbie but I would like to create a script in which I'd like to allow the user to select multiple options from a list of options.
Essentially what I would like is something similar to the ...
36
votes
8
answers
24k
views
Is there any reason to use bash over zsh? [closed]
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 ...
35
votes
5
answers
48k
views
Where is a good permanent place to install custom Bash scripts?
I'm about to install Leiningen which is a useful Bash script for the Clojure programming language.
The problem is, I'm not sure where it is appropriate to put a executable script in the Linux system ...
31
votes
14
answers
21k
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?
31
votes
12
answers
114k
views
How to find the gateway IP address in Linux
What command can you use to find the Gateway IP Address (ie. home router address) for eth0 in Linux?
I need to get the IP address from a command line app to use in a shell script.
31
votes
4
answers
60k
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:
...
30
votes
8
answers
105k
views
How to use a config file (ini, conf,...) with a PowerShell Script?
Is it possible to use a configuration file with a PowerShell script?
For example, the configuration file:
#links
link1=http://www.google.com
link2=http://www.apple.com
link3=http://www.microsoft.com
...
29
votes
10
answers
11k
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 ...
29
votes
5
answers
4k
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 ...
27
votes
3
answers
98k
views
scp files and delete files on remote directory [closed]
I am a unix noob, so please be patient :-)
I have a script that scps a bunch of files to another server.
Suppose they are z1.foo, z2.foo etc. What I want to do is to scp files and delete files older ...
26
votes
13
answers
104k
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 &...
26
votes
13
answers
1k
views
How to encourage Windows administrators to pick up scripting? [closed]
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 ...
26
votes
5
answers
16k
views
Send bash -x output to logfile without interrupting standard output
Is there a way to send the information displayed by running a bash script with the -x option to a file, while not changing the standard output seen by a user running the script?
This is a debugging ...
26
votes
15
answers
25k
views
Scripting alternatives to Bash shell scripts
I have just migrated to a UNIX workstation. My memory of Bash shell scripts has faded since school and I find the syntax to be highly confusing. I am wondering what other scripting languages are ...
25
votes
4
answers
202k
views
How to edit Local Group Policy with a script?
I have to set the local group policy settings and the the local security policy for a couple of machines which are not in a Windows domain. Until now, I've done that by manually setting the keys in ...
24
votes
4
answers
58k
views
How to automatically and temporarily block an IP address making too many hits on the server in a short timespan?
One of my LAMP servers was recently brought down by some kind of script bot looking for exploits. From the looks of it, it was making so many requests a second, that it overloaded the RAM on the ...
23
votes
5
answers
19k
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 ...
23
votes
5
answers
6k
views
Temporarily 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 and 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, ...
21
votes
7
answers
19k
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 ...
20
votes
9
answers
121k
views
script to automatically test if a web site is available
I'm a lone web developer with my own Centos VPS hosting a few small web sites for my clients. Today I discovered my httpd service had stopped (for no apparent reason - but that's another thread). I ...
20
votes
5
answers
100k
views
What version of Windows Management Framework is installed?
How do you check to see what version of Windows Management Framework (WMF) is installed? It seems like it should be a simple thing to find out, but I cannot. Even Googling a bunch of different ...
20
votes
1
answer
5k
views
Shell command slow when using pipe, fast with intermediate file
Does anyone understand this huge difference in processing time, when using an intermediate file, or when using a pipe? I'm converting tiff to pdf using standard tools on a fresh debian squeeze server. ...
19
votes
6
answers
146k
views
Find GUID of MSI Package
How can I find the GUID of an MSI package? I would like to script the removal of a program on a large number of desktops by using:
msiexec.exe /x ProductCode
Any reason why this would not work ...
19
votes
8
answers
54k
views
How to parse and convert ini file into bash array variables?
I'm trying to convert an ini file into bash array variables. The sample ini is as below:
[foobar]
session=foo
path=/some/path
[barfoo]
session=bar
path=/some/path
so these become:
session[foobar]=...
19
votes
14
answers
5k
views
What are some good resources for learning PowerShell scripting? [closed]
Are there online resources or books that you would recommend as an introduction to PowerShell scripting? The resources I've found primarily focus on interactive use.
19
votes
8
answers
2k
views
How do I become a scripting guy? [closed]
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
8
answers
73k
views
PowerShell prompt to continue execution of code
I have a script I am using to automate WSUS processes, and the last stage of it goes on to remove all old/unnecessary files/objects.
I would like to prompt 'Press 'Enter' to continue with removal or ...
17
votes
4
answers
6k
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:
...
17
votes
5
answers
27k
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 ...