Questions tagged [scripting]
A form of computer programming that — in the context of system administration — lends it self well to automating tasks.
112
questions
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:
...
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 ...
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?
16
votes
3
answers
137k
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 ...
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 ...
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. ...
11
votes
9
answers
31k
views
How to restrict the users' shell allowing to execute shell programs
Is it possible to prevent any user to not use commands like ls, rm and other system commands which could harm the system. But the users should be able to execute shell programs.
7
votes
6
answers
22k
views
Delete temporary files from batch script in xp
I'm looking for a good batch script that would quickly find & clean all the known safe temporary folders/files from Windows (as many variants as possible) machines (e.g. the windows temp folder, ...
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 ...
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 ...
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....
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
...
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. ...
15
votes
3
answers
47k
views
Dismount USB External Drive using powershell
I am attempting to dismount an external USB drive using powershell and I cannot successfully do this. The following script is what I use:
#get the Win32Volume object representing the volume I wish to ...
11
votes
3
answers
31k
views
Powershell Parameters
I have a Param block in my script
Param (
[Parameter(Mandatory=$True)]
[string]$FileLocation,
[Parameter(Mandatory=$True)]
[string]$password = Read-Host "Type the password you would ...
8
votes
3
answers
30k
views
Is it possible to use Puppet to ensure multiple files in a directory are present without defining all of them?
I have a couple hundred one-off servers that have different configuration files that need to be present in a directory. Copies of the files reside on the puppet master.
Within one of my classes I ...
8
votes
4
answers
21k
views
Is it possible to run a command on windows server from Linux?
I want to restore a sqlserver db backup on remote windows server from linux. I tired "net rpc" but there is nothing for execute a command or script on remote server.
6
votes
3
answers
5k
views
Can I "register" python scripts to execute on Windows?
I have Python 2.5 installed on Windows XP and a collection of scripts available in a certain directory. According to this article by Amanda Birmingham I can setup up a path for the Python executable ...
6
votes
2
answers
4k
views
Tips for optimizing RHEL/CentOS kickstart workflow
I'm working in an environment that consists of CentOS systems located in multiple data centers and office locations. I've been using a reasonable kickstart with a solid post-install script, but want ...
5
votes
3
answers
33k
views
How to switch proxy settings via script?
There are a number of users in our organization that use their laptops on multiple networks. Each network has its own proxy setting requirements for accessing the Internet and currently, the users ...
4
votes
2
answers
328
views
Repartitioning two disks without a loss of data
I am interning at a software company and I have hit somewhat of a brick wall. Here is the deal:
The Problem: We have some boxes around here that were incorrectly partitioned for 2 x 500 GB drives. ...
4
votes
4
answers
1k
views
Linux: How to change the extension of a bunch of files?
I have a directory full of files ending with .xxx. (Apple.xxx, Orange.xxx, Bannana.xxx)
I want to change their extensions to .yyy. (Apple.yyy, Orange.yyy, Bannana.yyy)
What's the quickest way to ...
3
votes
7
answers
49k
views
Batch file to MASS ping group of computers on network by name, check reply, and resolve hostname
So, I have a list of 5000 computers on my Windows Active Directory network that may or may not still exist (I know, don't ask...I need to know for a project, and of course little help from the network ...
2
votes
2
answers
5k
views
compare the contents of two folders that are replicating by dfs
I have a large folder that I am replicating by dfs and I want to check that all files have been replicated correctly.
Currently I am running the following script at both ends.
cd e:\data\shared\
dir ...
1
vote
3
answers
6k
views
proxy script does not work when two networking cards are connected. How to fix this?
I have deployed a wpad.dat. Works like a charm except for some users that are connected to two networks at the same time (ethernet and another networkadapter that emulates an analog modem for fax). I ...
1
vote
1
answer
15k
views
replacing a line or date in a text file using powershell
I am trying insert today's date on a text file at line 59. How do i do this?
Line 59 has like 30 spaces and then reads like this. After the PowerShell script runs it will change the date so it has to ...
0
votes
1
answer
6k
views
How can I set the 'The other domain supports Kerberos AES Encryption' setting programmatically?
In the GUI (Active Directory Domains and Trusts MMC Snap-in (domain.msc)), you can set the "The other domain supports Kerberos AES Encryption" setting for a trust relationship:
I am looking ...
0
votes
1
answer
386
views
Linux (CentOS) - Is there any (feasible) way to add a file write "hook"?
I have a mod_security log parsing script to load data into a mysql database which is then accessed by our Project Management System to display recent flaggings by the rulesets for our developers.
The ...
-2
votes
1
answer
340
views
shell script doesn't run correctly in cron [closed]
I want to call a shell script I wrote from a cron. The shell script uses the program Linkchecker. If I run the shell script from the terminal it works just fine. However, when cron runs I get the ...
-3
votes
2
answers
3k
views
How to compare today's date against an array of dates [closed]
I want to create an array of dates and compare it to today's date if it matches then execute test.sh file otherwise exit the loop in bash script.
I have this so far:
#!/bin/bash
now=$(date +%Y-%m-%d)
...
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-...
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.
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 -...
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 ...
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 ...
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 ...
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 ...
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 ...
15
votes
6
answers
15k
views
How can I easily convert HTML special entities from a standard input stream in Linux?
CentOS
Is there an easy way to convert HTML special entities from a data stream? I'm passing data to a bash script and sometimes that data includes special entities. For example:
"test" &...
14
votes
6
answers
22k
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 ...
14
votes
5
answers
33k
views
Bash: Quotes getting stripped when a command is passed as argument to a function
I am trying to implement a dry run kind of mechanism for my script and facing the issue of quotes getting stripped off when a command is passed as an argument to a function and resulting in unexpected ...
12
votes
4
answers
21k
views
gpg-agent says agent exists, but gpg says agent doesn't exist?
I'm struggling with some issues while scripting gpg with bash on a Debian 6.0.6 box. I have a script that does a batch of operations and wants to make sure that a gpg-agent is available before it ...
10
votes
3
answers
7k
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
2
answers
7k
views
Changing physical path on IIS through appcmd isn't activated
We have come across an issue on IIS 7.5 where we have a simple deploy system which consists of the following:
Create a zip-file of new webroot, consisting of three folders:
Api
Site
Manager
This is ...
9
votes
11
answers
17k
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
2
answers
23k
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
3
answers
9k
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
1
answer
8k
views
How do I remotely issue a CLI command to thousands of Windows domain computers at once?
I need to issue a CLI command (cmd.exe or PowerShell) to all of the thousands of computers on my domain. For obvious reasons, this is not going to involve doing the task manually, or physically ...
6
votes
2
answers
3k
views
How To Shutdown Ubuntu Automatically X Minutes After Starting Up?
How would one automatically shutdown an ubuntu OS 30 minutes after it was turned on? Or 15 minutes after it was turned on? Etc?
I tried creating an init.d script like so:
shutdown -h +5
But my box ...