Questions tagged [scripting]

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

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

Scripting is usually done in a scripting language. Such scripting languages are often dynamically typed and interpreted, as opposed to compiled languages. Examples of such languages include PowerShell, Perl and Bash.

1826 questions
980
votes
15 answers

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 straightforward)
Brent
  • 22,857
  • 19
  • 70
  • 102
547
votes
5 answers

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 bash.
0x89
  • 6,465
  • 3
  • 22
  • 14
183
votes
10 answers

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-linux-gnu) Copyright (C) 2009 Free Software…
Maxim Veksler
  • 2,725
  • 10
  • 28
  • 32
168
votes
11 answers

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 managed to make the window appear minimized by making…
102
votes
8 answers

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.
Epeius
  • 1,031
  • 2
  • 9
  • 6
95
votes
9 answers

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 admin@server.com 'bash…
BlueMark
  • 1,089
  • 1
  • 9
  • 8
85
votes
6 answers

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 documented?
imaginative
  • 1,971
  • 10
  • 32
  • 48
83
votes
12 answers

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 -tq myuser@hostname "sudo -u scriptuser bash -c…
VoY
  • 1,275
  • 2
  • 11
  • 9
83
votes
7 answers

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. But, are there any other advantages over shell…
resting
  • 1,059
  • 3
  • 10
  • 10
61
votes
9 answers

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? Scenario: A server service account's password is…
TheCleaner
  • 32,627
  • 26
  • 132
  • 191
59
votes
8 answers

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.sh /tmp/test exit Since I want to automate the…
Wadih M.
  • 1,032
  • 1
  • 10
  • 18
56
votes
9 answers

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 would find with tools like cfengine, but on a set of…
tremoloqui
  • 1,303
  • 1
  • 10
  • 9
54
votes
10 answers

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.
Catskul
  • 1,929
  • 4
  • 20
  • 23
54
votes
5 answers

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 proceeding to the next one” $DName = Read-Host…
Paul Masek
  • 722
  • 2
  • 7
  • 16
44
votes
4 answers

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. The idea is that when I run rsync, I can output…
Jason M.
  • 565
  • 1
  • 5
  • 7
1
2 3
99 100