The tag has no wiki summary.

learn more… | top users | synonyms

11
votes
4answers
1k 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 ...
9
votes
3answers
12k views

How do I sleep for a millisecond in bash or ksh

sleep is 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 ...
5
votes
3answers
117 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 ...
5
votes
1answer
178 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 ...
4
votes
2answers
164 views

supress expansion of * in echo

I am working on a script which dynamically executes some queries on daily basis. These queries are coming from a table in the database. Here is the sample output of the query table: ...
4
votes
3answers
1k 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/ | ...
4
votes
2answers
1k 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 ...
4
votes
3answers
163 views

Detect fails in setup script

I wrote a setup script to install my prefered programs and settings after I got a new server. apt-get install git git clone http://me@myvimsetting.github.com .vim ln -s .vimrc .vim/vimrc ... But if ...
4
votes
1answer
165 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 ...
4
votes
1answer
120 views

Shell script: the child process do not terminate in linux

I have written a shell script to initiate three background process in the same time. In shell script I am trying to wait for all children to finish their job and then the parent job to terminate. But, ...
4
votes
2answers
559 views

Shell script: Find entries in access log with 500 response within a specified date period

Can someone help me with a shell script to figure out the number of 500 HTTP response entries in an access log within a time frame specified?
4
votes
2answers
2k 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 ...
4
votes
3answers
3k 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 ...
4
votes
3answers
738 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 # ...
4
votes
2answers
975 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 ...
3
votes
2answers
3k 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 & ...
3
votes
4answers
2k 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 ...
3
votes
1answer
143 views

echo $? doesn't work when executed remotely

When I execute a command as below it gives me an output as expected but when I run the same command on remote server it always gives me echo $? as 0. locally # <some command> # echo $? ...
3
votes
2answers
7k 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 ...
3
votes
3answers
562 views

Email to run a bash script

I have a bash script to restart a service that runs every 3am to guarantee that the service isn't crashed when users require it. However, I need to provide a simpler way for my partner (that isn't ...
3
votes
1answer
1k 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 ...
3
votes
2answers
1k 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 ...
3
votes
1answer
164 views

shell script (KSH) + set file to param & perform test between param and string

in my linux machine red-hat 5.1 - in ppp file - I have only the signature.pl string !!! remark - third application write the signature.pl string in to ppp file I set ppp file in $a param And ...
3
votes
1answer
357 views

How can I output the chkconfig results to a file within a shell script?

When I run the following from the linux command line it works properly and populates the chkconfig.bak file correctly : #chkconfig --list > chkconfig.bak But when the command is run from a ...
3
votes
2answers
216 views

Measuring “loading time in milliseconds” every minute

I have apache running on a virtual server, which in periods gives very bad performance - even when retrieving static JPG or PNG files. This only happens once in a while, so it's hard for me to ...
2
votes
5answers
748 views

bash + print line every 10 min in bash

I want to print by echo the following "still in process wait another 10 min" every 10 min Please advice what condition needs to add before the echo command in order to print this line every 10 min? ...
2
votes
2answers
513 views

Date calculation in linux

In linux how to get the date of the first day of the week monday. I know that date +"%u" gives the current day of the week from this how to get the date of the monday of that week
2
votes
3answers
168 views

bash + how to match string that include characters and numbers

please advice - what's wrong with my syntax ? ( should not print the "bad interface " ) remark - I work with bash shell ETH_NAME=eth0 ( or any other as eth1 or eth2 .... ) echo $ETH_NAME ...
2
votes
4answers
617 views

how to change permissions of specific file type

file * | grep 'ASCII text' | chmod -x chmod: missing operand Try `chmod --help' for more information. The above command gives me error.Basically I am trying to find all the files whose type is ...
2
votes
1answer
351 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 ...
2
votes
2answers
2k views

What is wrong? “Syntax error: unexpected end of file”

I keep getting this error, do you guys know what is wrong? rapache is an alias for restart apache mugbear:/usr/bin# cat /usr/bin/mkdomain if [ -d ...
2
votes
1answer
964 views

problem executing a bash script with utf8 encoding

I have a bash script encoded in utf8 . Within the script i use sed command using ยง as a separator . Now when i run execute this script sed complains about the separator. If i use normal char as a ...
2
votes
3answers
81 views

power shell error: Cannot bind parameter

when i am trying to execute the below PowerShell command, i got error . The command : *PS cert:\currentuser\authroot> gci | where subject -like "UTN"* The error is below : Where-Object : Cannot ...
2
votes
3answers
629 views

In zsh, how do you redirect stderr to /dev/null within a for or foreach loop?

I am trying to accomplish something that is easy in bash: look for files in a folder and source them if they exist (and do not output if no files exist). In bourne shells this is how to do it: if ...
2
votes
2answers
2k 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 ...
2
votes
2answers
151 views

awk + perl + get two arguments in to awk syntax

please advice what wrong with my awk syntax and how to fix it ( this syntax is in my ksh script ) and I run my script on linux machine my target is to get from the file.txt only the lines that ...
2
votes
2answers
539 views

Init script & the green [ OK ]

I am trying to install fast-cgi for nginx on an EC2 instance. I followed the steps explained here, but that is meant for Debian and does not work out of the box for a red-hat based system. I modified ...
2
votes
2answers
179 views

Tomcat server getting restarted frequently

We have a script like below to monitor our server. During this code our server getting restarted. Can anyone please explain the meaning of below script? if [ -f $HOME/catalinamonitor ]; then echo ...
2
votes
1answer
92 views

Move all files to their own folder

Is there any way on a linux box to move every file in a directory into their own sub directory (i.e. make a directory named after it and move it in)?
2
votes
4answers
784 views

How to lock user in a shell script program?

Let's say I have a Linux OS without desktop environment. After the PC finish boot up, it will directly show the shell terminal to the user. I plan to write a shell script program and make it ...
2
votes
1answer
65 views

Hold till last command completes its execution

I am developing a shell script which actually stops aws running instances in a particular region & start them again as a part of schedule maintenance. but as ec2-api tools are heavy, takes time to ...
2
votes
1answer
1k 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 ...
2
votes
6answers
105 views

Copying files from a server to a set of machines

First of all I am not a trained professional in Networking nor I know much about it. I have some knowledge of GNU/Linux, Shell scripting. One day I wanted to copy a large zipped file to a set of ...
2
votes
3answers
701 views

Shell script to scan size of directories and email when too big

I am at work right now, and my superiors asked me to write/find a shell script for the Red hat Server edition that checks a folder size, and if it's above a certain limit, it will send an email.Can ...
2
votes
3answers
2k 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 \ ...
2
votes
4answers
216 views

Bash one-liner that shows a running countdown until a DNS update (TTL expiration)

I find myself frequently tasked with updating DNS records and needing to know exactly when the refresh will begin (a.k.a TTL expiration). I came up with this bash one-liner that gives me the output I ...
2
votes
1answer
82 views

How do I find the biggest files on multiple servers and sum up their size?

I am trying to find the biggest files in the /export/home directory and add up (sum) their sizes. Script: #!/bin/bash filename=hostnames > export_home.log while read -r -a line do ...
2
votes
2answers
514 views

trap “” HUP v.s Nohup ? How can I run a portion of shell script in nohub mode?

I want to run a shell script over the weekend, but I wanna make sure if the terminal loses the connection, my script won't be terminated. I use nohup for the whole script invokation, but I also want ...
2
votes
1answer
70 views

Terminate remote process when backgrounded ssh session is terminated

So right now I have a bash script that runs a command on a remote machine using ssh. The machine running the bash script is a Linux machine and the remote machine is a Windows machine running cygwin. ...
2
votes
2answers
826 views

How can I kill and wait for background processes to finish in a shell script when I Ctrl+C it?

I'm trying to set up a shell script so that it runs background processes, and when I ctrl+C the shell script, it kills the children, then exits. The best that I've managed to come up with is this. It ...