Questions tagged [shell-scripting]

Programming in an Interpreted language executed by a running Shell

Filter by
Sorted by
Tagged with
179 votes
8 answers
403k views

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 ? ...
yael's user avatar
  • 2,443
46 votes
6 answers
50k views

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-...
kenn's user avatar
  • 675
30 votes
2 answers
40k views

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 ...
Justin Ainsworth's user avatar
26 votes
9 answers
54k views

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 ...
Dan's user avatar
  • 667
22 votes
2 answers
25k views

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 ...
Jonik's user avatar
  • 2,981
22 votes
1 answer
11k views

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 ...
kolypto's user avatar
  • 11.1k
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. ...
plang's user avatar
  • 325
19 votes
7 answers
32k views

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@...
Mauro's user avatar
  • 386
18 votes
2 answers
7k views

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-}" ]...
Matt Huggins's user avatar
17 votes
3 answers
24k views

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 ...
krunal shah's user avatar
16 votes
4 answers
13k views

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 . -...
Dan Monego's user avatar
14 votes
2 answers
36k views

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 ...
saji89's user avatar
  • 255
14 votes
6 answers
37k views

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 ...
ReynierPM's user avatar
  • 720
14 votes
3 answers
31k views

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 ...
Addy's user avatar
  • 161
13 votes
3 answers
7k views

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 ...
Adam's user avatar
  • 233
12 votes
5 answers
6k views

Can a shell script wait for a file to change and take action?

I wonder if I can write a script that will monitor for a change in a file and execute some action when the change is detected. Detailed explanation: OpenVPN writes its status to a file every 1 ...
davidparks21's user avatar
11 votes
5 answers
17k views

Silent and scripted install of CPAN and Perl modules?

I need to install CPAN and some Perl modules automatically in a Scientific Linux (RHEL) installation script. Unfortunately the specific modules I want (at least one of them) cannot be found as RPM:s ...
Mikael Grönfelt's user avatar
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 ...
TechGuyTJ's user avatar
  • 792
11 votes
2 answers
13k views

Can I change the ownership of all the files of a specific user?

Is there a way to recursively find all files owned by a user and change them to another user/group in Gnu/Linux? I assume there must be some magic one liner but my command line wizardry skills are ...
john's user avatar
  • 1,025
11 votes
4 answers
30k views

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

I need to use openssl to perform some HTTP GET requests in a shell script. The line I'm using to do this right now is shown below. This is parsing the content of an XML response of the following ...
conorgriffin's user avatar
9 votes
4 answers
39k views

control a bash script with variables from an external file

I would like to control a bash script like this: #!/bin/sh USER1=_parsefromfile_ HOST1=_parsefromfile_ PW1=_parsefromfile_ USER2=_parsefromfile_ HOST2=_parsefromfile_ PW2=_parsefromfile_ imapsync \ -...
perler's user avatar
  • 531
8 votes
5 answers
4k views

Run a script from anywhere

I have a script: #!/bin/bash echo "$(dirname $(readlink -e $1))/$(basename $1)" that sits here: /home/myuser/bin/abspath.sh which has execute permissions. If I run echo $PATH I get the following: /...
Cheetah's user avatar
  • 241
8 votes
3 answers
58k views

How to run a script automatically on system startup in centos

I've successfully installed TeamCity ib CentOS 6.2 Minimal. I'm stuck on trying to run a script automatically on system startup: /opt/TeamCity/bin/teamcity-server.sh start I've googled around and ...
atp03's user avatar
  • 209
8 votes
3 answers
15k views

From a shell script, how can I check whether a table in MySQL database exists or not?

I am trying to write a script which allows a user to select the what manipulation he needs to do on a table. I want to check if the table exists or not. If it exists I will continue the other things ...
RathanKalluri's user avatar
8 votes
4 answers
3k views

Loop through servers and run command

I have a set of servers mentioned in a text file called network_list.txt . How can i run through the servers and run command and display the result ? I have tried the follows : filename="network_list....
KTM's user avatar
  • 213
8 votes
3 answers
18k views

"watch" command to notify on newly created files on linux

watch command to notify on newly created files on linux How to modify the below command to notify on creating a new file to /usr/local/mydir/ by linux user john ? watch -d 'ls -l /usr/local/mydir/ | ...
Aha's user avatar
  • 409
8 votes
1 answer
3k views

using temporary files vs pipes advantages and disadvantages

Say I have a file named jobs.csv and I would like to get the top 50k jobs done by Foo I can either do: # cat jobs.csv | sort -u | head -n 50000 > /tmp/jobs.csv # cat /tmp/jobs.csv | while read ...
Tzury Bar Yochay's user avatar
7 votes
3 answers
7k views

Echo each shell script command with a timestamp

set -x or set -v prints every executed command. How do I get the command printed with the time when the command started executing?
warvariuc's user avatar
  • 358
7 votes
2 answers
14k views

expect script + expect miss the send string + delay issue

I write the active.ksh script (based on expect) in order to login automatically to some Solaris machine and execute the hostname command (login to virtual IP in order to verify which hostname is the ...
Eytan's user avatar
  • 611
7 votes
2 answers
26k views

Shell script for docker ps -a | grep to find number of certain containers running

I want to write a script that is executed by my development build server that will remove any 'similar' docker containers before building and running a new container. Below is pseudo code for the ...
TheJediCowboy's user avatar
7 votes
3 answers
4k views

How to delete docker images older than x days from docker hub using a shell script

How to delete docker images from docker hub using a shell script. I want to delete all images from docker hub older than past 50 days of a private docker hub account. Any ideas? Which tools to use ...
amit's user avatar
  • 101
6 votes
4 answers
2k views

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

I have a domain name in a bash variable ($TARGET), and I want to get the IPv4 (A record) address of it in my bash script (I also want to get the IPv6 AAAA record (if exists)), in a robust manner. i.e. ...
Amandasaurus's user avatar
  • 31.9k
6 votes
3 answers
6k views

Simple dig output?

In a script I want to be able to write an IP address to somewhere easily, so I thought using dig (or a similar command) with back-ticks. However the simplest output I've been able to come up to wrt ...
knocte's user avatar
  • 357
6 votes
2 answers
17k views

Linux FTP upload: "No such file or directory", but file exists

I want to upload backup archives from one server to another server using ftp. In my backup cronjob I use this script to upload files: MEDIAFILE=/var/somedir/somefile.encrypted if [ -r $MEDIAFILE ] # ...
i.amniels's user avatar
  • 325
6 votes
4 answers
17k views

Incrond running but not executing commands CentOS 6.4

I have copied this question over here from StackOverflow... I have installed incron from the EPEL repository (0.5.9) (before you ask; YES, I also tried downloading the source and compiling locally (0....
JawzX's user avatar
  • 91
6 votes
1 answer
1k views

perl equivalent of sh -e

In /bin/sh and /bin/bash (and I guess a lot of other shells), starting scripts with #!/bin/sh -e (or executing set -e in someplace in the script) would cause the script to abort when any command line ...
Carlos Campderrós's user avatar
6 votes
3 answers
348 views

Returning A List Of Quoted Files Paths Using Find

I would like to create a tarball that contains files from a directory that have a ctime of less than 30 days. Most tutorials I have found have basically recommended doing something like this: tar cvf ...
Tom Purl's user avatar
  • 549
6 votes
1 answer
1k views

Is it possible to listen to a TCP port only with a shell, with no additional tools? [closed]

I need a very simple web server on a very small embedded system with a MISP processor. I thought that the simplest server could be a shell script listening to a TCP port. The problem is that the ...
d.k's user avatar
  • 285
6 votes
1 answer
421 views

identifying ssh trusts between multiple servers on a network

The problem: We have many dev/qa/prod RH/Solaris servers with many accounts having ssh trust between them, including between servers in different environments (prod->prod, but also qa->prod). I know ...
Alex's user avatar
  • 161
5 votes
2 answers
15k views

ssh fails to execute remote command when run from cron bash script - works from CLI

I have a script, written in bash, which runs from cron. One of the first things it does is SSH to a remote host and retrieve a list of files in a directory. Everything works fine when run from the ...
Kyle Smith's user avatar
  • 9,733
5 votes
1 answer
12k views

How can I replace line #6 in a text file in a bash script?

I have a text file that is generated by 3rd-party software as part of a build process. I want to replace one specific line - in my case, line 6. How can I do this in my bash script? I suspect sed is ...
Steve McLeod's user avatar
5 votes
1 answer
3k views

Closing All Shared Files on the Network [duplicate]

I am trying to close all of the open files in the shared folders of a server via PowerShell script. I found the following script which only close files on one drive (F:), however, this server has 3 ...
eccoripo's user avatar
5 votes
2 answers
5k views

linux + how to identify if file is pointed by link/s

I create new file called - 192.9.200.1 touch 192.9.200.1 then I create new link that will be pointed to 192.9.200.1 file ln -s 192.9.200.1 file so finally I get: ls -ltr /tmp -...
yael's user avatar
  • 2,443
5 votes
2 answers
5k views

Installing and configuring phpmyadmin completely through a shell script

Referencing this tutorial: https://www.liquidweb.com/kb/how-to-install-and-configure-phpmyadmin-on-ubuntu-14-04/ for installing PHP-Admin, after installing the package, on "Step 2: Basic Configuration"...
Rodrigo's user avatar
  • 51
5 votes
3 answers
2k views

Bash-Scripting - Munin Plugin don't work

i have written a munin-plugin to count the http-statuscodes of lighttpd. The script: #!/bin/bash ###################################### # Munin-Script: Lighttpd-Statuscodes # ########################...
Arny80Hexa's user avatar
5 votes
2 answers
15k views

How properly handle deletion of pid.file in service script

I'm trying to write service script for application. So I can control it like this: ./myscript.sh start|stop|status On startup pid.file with process id creates, and based on it I can check status and ...
zella's user avatar
  • 153
5 votes
2 answers
4k views

expect + how to identify if expect break because time out?

The target of the following simple expect script is to get the hostname name on the remote machine Sometimes expect script fail to perform ssh to $IP_ADDRESS ( because remote machine not active , etc ...
Eytan's user avatar
  • 611
4 votes
2 answers
7k views

Unix separate multiple commands which has '&' (execute in background) in the end

To separate regular commands in Unix is to put semicolon in the end like this: cd /path/to/file;./someExecutable; But it seems not working for commands like this: ./myProgram1 > /dev/null & ....
Stan's user avatar
  • 1,397
4 votes
3 answers
5k views

Access windows file system from linux shell script

I want to know, whether is it possible to access the Windows files from a shell script on Linux system ? What i am trying to do is to run a shell script in my Linux system, that will access the files ...
shasi kanth's user avatar
4 votes
2 answers
4k views

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

I have developed the following script at location /usr/local/etc/rc.d/bluesky #!/bin/sh # PROVIDE: bluesky # REQUIRE: mysql sshd # BEFORE: # KEYWORD: . /etc/rc.subr name="bluesky" rcvar=...
Megidd's user avatar
  • 241

1
2 3 4 5
13