61 votes

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

Could not get @stone's answer to work. Instead, I use this method (for Dockerfiles): # Configure timezone and locale echo "Europe/Oslo" > /etc/timezone && \ dpkg-reconfigure -f ...
  • 611
30 votes

Silent and scripted install of CPAN and Perl modules?

Try setting this environment variable before running CPAN: export PERL_MM_USE_DEFAULT=1 It makes perl automatically answer "yes" when CPAN asks "Would you like to configure as much as possible ...
30 votes
Accepted

Run a script from anywhere

You want to type abspath, but the program is named abspath.sh. The problem is not regarding whether it is in the PATH, but the fact that you are simply not using its name to call it. You have two ...
21 votes

Running ssh-agent from a shell script

Put the following at the top of your script: eval `ssh-agent` Your script should look like this: #!/bin/bash eval `ssh-agent` ssh-add /path/to/key ... ... Explanation The backticks around ssh-...
20 votes
Accepted

How to compress this mysqldump?

I think you can just do this. /usr/bin/mysqldump -h $mysql_host -u $mysql_username -p$mysql_password $mysql_database | gzip -9 -c > $backup_path/$today/$mysql_database-`date +%H%M`.sql.gz
18 votes

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

Based on the fine work in @EirikW's answer. Specific to a Dockerfile: ENV LANG=en_GB.UTF-8 RUN apt-get install -y locales && \ sed -i -e "s/# $LANG.*/$LANG UTF-8/" /etc/locale....
  • 361
14 votes
Accepted

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

According to the section on "Parameter Expansion" in the bash man page, this means "use the default value if the parameter is unset." So for example, ${PID-/run/unicorn.pid} equals $PID if $PID is ...
13 votes

How do I sleep for a millisecond in bash or ksh

You may simply use usleep. It takes microseconds (= 1e-6 seconds) as parameter, so to sleep 1 millisecond you would enter: usleep 1000
11 votes

Robust way to resolve a DNS address in a script (IPv4 (A) and IPv6 (AAAA))?

I'm unsure if you want to actually query nameservers or rather rely on your system's name resolution: $ getent ahosts one.one.one.one. | awk '{ print $1 }' | sort -u 1.0.0.1 1.1.1.1 2606:4700:4700::...
  • 9,461
10 votes

Get list of transferred files from rsync?

Use the --out-format option According to the man page: Specifying the --out-format option will mention each file, dir, etc. that gets updated in a significant way (a transferred file, a ...
  • 201
10 votes

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

It should be emphasized that this means an unset variable. Not an empty one. And to put to comparison with :-, which will use default value (the one after minus sign) if variable is unset or null (as ...
  • 199
10 votes
Accepted

Automated graceful reload of gunicorn in production

Add the following to the systemd service file for gunicorn, or add it as an override: ExecReload=/bin/kill -HUP $MAINPID You can then reload with systemctl reload gunicorn.
  • 879
9 votes

Get list of transferred files from rsync?

Beginning with rsync v3.1.0, released in 2013, there is the --info flag which allows fine-grained control over the output. --info=FLAGS This option lets you have fine-grained control over ...
  • 203
9 votes
Accepted

shell script to delete 6 month old logs from log file

The solution really is to use logrotate: it works very well, and it can also compress the rotated log. If you really don't want to use logrotate, you had to manually cat/copy the relevant section of ...
  • 45.1k
8 votes

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

For me it was necessary to set the additional 3 ENV-Vars: # - Set the locale + timezone -------------------------------------------------- RUN echo "Europe/Vienna" > /etc/timezone && \ ...
8 votes
Accepted

How to schedule a Cron job for the second to the last day of each month

The code samples on that site are erroneous. They have certain shell characters replaced with HTML entities. The quotes also seem to be in the wrong places. I wonder if the author ever looked at that ...
8 votes
Accepted

FreeBSD rc.d script doesn't start as a daemon

The RC script itself is not intended to daemonize, but is expected to start and stop the daemon. If your service does not have an option to start as a daemon, you can use daemon(8) to manage that ...
8 votes

Loop through servers and run command

There is solution with -n -x parameters: http_status=$(ssh -nx name ps -ef | grep -v grep | grep $service | wc -l) The -x disables X11 forwarding to get rid of possible X11 forwarding request failed ...
8 votes
Accepted

Closing All Shared Files on the Network

The command you are using is not a native PowerShell command. However, PowerShell does come with a lot of functions to control SMB connections and shares. What you are looking for could be this: Get-...
  • 1,236
7 votes

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

To reconfigure the timezone and locales non-interactively, from within a script, here is what works for me (under Debian): For configuring the timezone, I first create '/etc/localtime' as a soft link ...
  • 71
7 votes

Using curl with cookies

It is possible that their website is authenticating the session stored in the cookies by redirecting them first to the login page. Then their login page will redirect back to the appropriate page as ...
7 votes
Accepted

Loop through servers and run command

You need to redirect the stdin of SSH command in your loop to nowhere to prevent reading all your lines. This should do it: http_status=$(ssh $name "ps -ef | grep -v grep | grep $service | wc -l" <...
  • 36.1k
7 votes
Accepted

Can't access instance after setting up iptables rules

For rules in the OUTPUT chain you should specify the source port match (--sport), not the destination port (--dport). Anyway DROP policy in the OUTPUT chain isn't a common practice. Read the iptables ...
7 votes

Robust way to resolve a DNS address in a script (IPv4 (A) and IPv6 (AAAA))?

You are on the right track with dig. You can suppress that particular cookie related error (per the man page). Below, I am also choosing to redirect all errors to /dev/null just in case, as you wanted ...
  • 196
7 votes

Robust way to resolve a DNS address in a script (IPv4 (A) and IPv6 (AAAA))?

getent ahosts[v4|v6] and generally anything that uses getaddrinfo() is the right answer, as it will use the same name resolution mechanisms (DNS, mDNS, NetBIOS, NIS, LDAP…) as the rest of the system, ...
  • 8,872
6 votes

Running ssh-agent from a shell script

I found this works for me. eval `ssh-agent` # create the process ssh-add ~/.ssh/priv_key # add the key git -C $repo_dir pull # this line is the reason for the ssh-agent eval `ssh-agent -k` # kill the ...
6 votes
Accepted

Why is my shell command not working?

The '' quotes prevent variable interpolation. Use "" instead. host:~ sven$ echo $USER sven host:~ sven$ echo '$USER' $USER host:~ sven$ echo "$USER" sven
  • 97.9k
6 votes

Echo each shell script command with a timestamp

In Bash, you can use PS4 - which is used by set -x to prefix tracing output. PS4='+ $(date "+%s.%N")\011 ' set -x ... \011 is the horizontal tab character
  • 161
6 votes

Check if remote mysql is running

Connect to mysqld using mysqladmin MySQL Documentation says about mysqladmin ping Check whether the server is available. The return status from mysqladmin is 0 if the server is running, 1 if it is ...
6 votes
Accepted

How can I use openssl to get results from HTTP GET requests?

What you really should be doing is using a tool designed for fetching Web resources, such as curl, wget, or libwww-perl's GET command. If nothing is available, you should have your system ...

Only top scored, non community-wiki answers of a minimum length are eligible