Questions tagged [shell-scripting]

Programming in an Interpreted language executed by a running Shell

Generic programming in an Interpreted language (as opposed to compiled) executed by a running Shell. Sometimes referred to as "Glue Code" due to the practice of managing the execution and output of one or more compiled binaries and passing said output to another series of commands.

603 questions
172
votes
8 answers

How do I sleep for a millisecond in bash or ksh

sleep is a very popular command and we can start sleep from 1 second: # wait one second please sleep 1 but what the alternative if I need to wait only 0.1 second or between 0.1 to 1 second ? remark: on linux or OS X sleep 0.XXX works fine , but…
yael
  • 2,363
  • 4
  • 28
  • 41
41
votes
5 answers

How do you set a locale non-interactively on Debian/Ubuntu?

Usually, I run aptitude -y install locales then dpkg-reconfigure locales to set up locale. Now I want to put it into a shell script, how can I reliably do the following, automatically / non-interactively? Choose en_US.UTF-8 and set it as system…
kenn
  • 625
  • 1
  • 5
  • 10
24
votes
9 answers

Running ssh-agent from a shell script

I'm trying to create a shell script that, among other things, starts up ssh-agent and adds a private key to the agent. Example: #!/bin/bash # ... ssh-agent $SHELL ssh-add /path/to/key # ... The problem with this is ssh-agent apparently kicks off…
Dan
  • 647
  • 2
  • 8
  • 12
22
votes
2 answers

Is it possible to set a timeout on openssl's s_client command?

I've got a script which uses openssl's s_client command to pull certificates for a big set of hosts. Some of these hosts will inevitably be unreachable because of a firewall. Is it possible to set the s_client timeout to something much shorter…
Justin Ainsworth
  • 323
  • 1
  • 2
  • 5
22
votes
1 answer

Ctrl-C in bash scripts

How do I implement ctrl+c handling in bash scripts so that the script is interrupted, as well as the currently running command launched by the script? (Imagine there's a script that executes some long-running command. The user hits ctrl+c and…
kolypto
  • 10,738
  • 12
  • 51
  • 66
22
votes
2 answers

How to grant sudo rights only to specific script files?

I would like a user to have sudo rights (without password check) to a couple of shell scripts under a specific directory (in my case, /usr/local/tomcat7/bin), and to nowhere else. What's the simplest way to accomplish this? Something like this in…
Jonik
  • 2,911
  • 4
  • 37
  • 48
20
votes
1 answer

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. A standard way of doing this is to convert to ps…
plang
  • 325
  • 3
  • 10
17
votes
7 answers

Get list of transferred files from rsync?

I'm currently using rsync on a script that deploys a PHP application from a staging to a production server. Here is how: rsync -rzai --progress --stats --ignore-times --checksum /tmp/app_export/ root@app.com:/var/www/html/app/ This is currently…
Mauro
  • 356
  • 1
  • 3
  • 13
17
votes
3 answers

Does mysqldump return a status?

I am creating a script that backups a mysql db using the mysqldump utility. I am writing this script in the shell "sh". I would like to capture the output status of mysqldump in the script (i.e. if the mysqldump command failed or succeeded) so I can…
krunal shah
  • 335
  • 1
  • 3
  • 13
16
votes
4 answers

How to use find command to delete files matching a pattern?

I'm trying to write a bash command that will delete all files matching a specific pattern - in this case, it's all of the old vmware log files that have built up. I've tried this command: find . -name vmware-*.log | xargs rm However, when I run the…
Dan Monego
  • 285
  • 1
  • 2
  • 7
14
votes
3 answers

How to pass command output as several arguments to another command

I have a command that produce a output like this: $./command1 word1 word2 word3 I want to pass this three words as arguments to another command like this: $ command2 word1 word2 word3 How to pass command1 output as three different arguments $1 $2…
Addy
  • 161
  • 1
  • 1
  • 5
14
votes
2 answers

How to set postgresql user password in bash script

I want to set a password for the default Postgresql server user, postgres. I did it by using: sudo -u postgres psql # \password postgres I want to do this step in many machines, so I would like to create a bash script to do the same. How to…
saji89
  • 255
  • 1
  • 2
  • 8
13
votes
2 answers

What does a minus sign inside of dollar brackets of a shell script mean?

In an existing shell script, I'm seeing some variables referenced that either include or end with a minus sign. For example: PID=${PID-/run/unicorn.pid} and: run_by_init() { ([ "${previous-}" ] && [ "${runlevel-}" ]) || [ "${runlevel-}" = S…
Matt Huggins
  • 517
  • 4
  • 13
13
votes
6 answers

Connect to MySQL through command line without using root password?

I'm building a Bash script for some tasks. One of those tasks is create a MySQL DB from within the same bash script. What I'm doing right now is creating two vars: one for store user name and the other for store password. This is the relevant part…
ReynierPM
  • 700
  • 5
  • 14
  • 28
12
votes
3 answers

Automated graceful reload of gunicorn in production

I have an automated deployment workflow that pushes code out to my production servers and triggers database migrations, static file updates, etc. Problem is, gunicorn doesn't automatically reload code changes without the development option --reload,…
Adam
  • 223
  • 2
  • 7
1
2 3
40 41