0
votes
1answer
27 views

Bash function hangs while command run perfectly without function

Following function hangs : ssh() { local RESULTS; RESULTS=$(ssh $USERNAME@$SERVER $SSH_COMMAND1); echo $RESULTS; } ssh; while if i run following commands they work fine : ...
0
votes
1answer
78 views

ways to automatically fix line endings in shell scripts or files who break with ^M

Problem We regularly break our files lines endings and things stop working without us noticing. Bash complains about "invalid option" or ": command not found" as described here: ...
0
votes
0answers
28 views

Bash Script issue : Discrepancy in output when executed via cron [duplicate]

I have written a bash script that writes date and database size of a DB to a text file. The script is executed via cron every week. There is some discrepancy in the output that is being generated . I ...
1
vote
1answer
53 views

Replacing LineFeed \x0a with SED

I have to delete lots of Linefeeds (Hex \x0a) in a logfile. I just have sed to solve the problem. It is a bit complicated I know.. Do you have idea how to solve the problem? Here is an example ...
0
votes
3answers
89 views

Bash script: compare paths issue

I'm working on the bash script that iterates over the list of files. I need to compare the paths to this files with the array containing the restricted paths. Inside the for loop I get a path to a ...
2
votes
1answer
154 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. ...
0
votes
2answers
110 views

Script for search string inside the file for every one hour

I need to write a script where the particular string(alphanumeric) should be searched inside the file with every hour for whole day. And the search should not contain the previous hour results. Time ...
1
vote
1answer
71 views

Wrangling sed to find and reformat login date (or, how to kill idle mosh-server processes)

I have an old method of killing idle mosh-server processes, which doesn't work on my new VPS. Here's the old method, which I run in root's crontab to clean up mosh processes that have been idle for ...
0
votes
2answers
416 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 ...
1
vote
2answers
266 views

How can I make ssh wait until the command exits? [closed]

I have a script that looks like this: SERVER="RHT372 RHTl373 RHT374 RHTl375" case $1 in "stop") for SERVER in $SERVER do echo "================================================" echo ...
1
vote
0answers
72 views

error in killing tshark from shell script

I'm getting this error "* glibc detected * /usr/sbin/tshark: double free or corruption " while doing this, any idea why? #!/bin/bash trap 'my_exit; exit' SIGINT SIGQUIT count=0 /usr/sbin/tshark -i ...
1
vote
2answers
175 views

Adding sleep / delay between iptables blocks in shell script

On one server, we're trying to block any access for the country China. We wish to implement this with iptables rather than via .htaccess. The problem we're experiencing though, is that when adding ...
3
votes
4answers
254 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 ...
1
vote
1answer
53 views

Cronjobs putting archive in wrong directory

I am running a website on an Amazon ec2 instance running the default Debian linux. I set up a cronjob to copy the site files, take a database imprint, and zip them up. I want to keep the file ...
2
votes
1answer
72 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 ...
-1
votes
2answers
617 views

Shell script :: Reading a column from file & store it in array [closed]

I am working on shell script where i want to store O/P of the command in array. I have a file containing rows & columns from where i want to extract 3rd column & store all values in a array. ...
1
vote
5answers
102 views

linux how to tell the process for a script?

I ran a script postData.sh, but when I do "ps -ef", I don't see the script in the list of programs running but I do see extra -bash processes running. How do I determine the pid so I can kill the ...
0
votes
1answer
174 views

Nagios: bash is missing

I'm monitoring NTP server with nagios and nrpe, at the nagios server, when I get the following error: Service Status UNKNOWN Status information I am missing an important component : bash The plugin ...
2
votes
1answer
99 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 ...
1
vote
1answer
77 views

nice command - are other commands executed with script also niced?

A quick question about how nice works. Say if I have a script that runs in the crontab like so 0 4 * * * nice -n 19 /usr/local/admin/script.pl It is set to the lowest priority. This script will ...
-1
votes
1answer
96 views

Can not seem to get expr substr to work

Can anyone tell me what I am doing wrong ? [ /jlr/sub/libexec/vmr-staging ] $ expr substr "onetwothree" 1 4 expr: syntax error I got the syntax from http://stackoverflow.com/a/220464/1150847
0
votes
1answer
105 views

Recursively delete empty folders with verbose output

This should be fairly simple, but I am not sure what i'm missing. I'd like to recursively delete empty directories, and get an output for what's being deleted, this command works for sure, but I just ...
0
votes
1answer
206 views

Bash: php comand not found when called from a script run with sudo

I have this weird problem. The php command is not found in one specific sitiation. I try to call the command in three different ways. Only one of them fails: Being user john I create a simple ...
1
vote
2answers
32 views

script reading from new descriptor in read

I have a script that asks some questions to the user and repeats the question until the user has answered something appropiate. This is done with an infinite loop that is break'd when an acceptable ...
0
votes
1answer
201 views

can't access sourced variables inside Upstart script stanzas

I'm trying to use the variables defined in /etc/environment in an upstart script. I'm able to export the variable to the child process but for some reason I not able to use them in the upstart script ...
1
vote
2answers
136 views

re-create new link and remove the old link on one command

according to ln manual page: man ln -f, --force remove existing destination files so as I understand if I want to re-create new link to some destination directory/file I can ...
0
votes
4answers
121 views

How to automatically clean up date stamped logs

I have an apache web server with various virtual hosts. Each virtual host logs to date stamped files using cronolog. The result is that I end up with a lot of files like this: ----rw-r-- 1 root ...
1
vote
2answers
472 views

shell script in crontab, not all output being logged

I've got a simple shell script that runs a few LFTP commands and processes the files. When running straight from bash I get full output of those LFTP commands on screen. When running from crontab ...
-2
votes
1answer
96 views

case + how to implement equal or less or greater in case syntax

my target is to verify the range of number with (only with - case + esac ) , and print the range so for example if number is between 0-80 , case will print >=0<=80 or if range is ...
1
vote
4answers
69 views

Howto: command/tool ability check

When developing a shell script that should run on various unix/linux derivates, i sometimes have the problem that some tools have to be called in a different way compared to other systems. For example ...
1
vote
1answer
84 views

escaping spaces in shell script

yesterday="2010-06-23 00:00:00" today="2010-06-24 00:00:00" mywhere="lastupdate>'$yesterday' and lastupdate<'$today'" mysqldump $param ticket --no-create-info --where=\"$mywhere\" The last ...
3
votes
1answer
152 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 $? ...
10
votes
4answers
18k 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 ...
0
votes
1answer
157 views

How to combine outputs of ps and lsof

Usually output of ps has a pid somewhere. Is there a way to combine this, preferably with a one-liner, with an output of lsof ? e.g. 27915 ? Ss 0:03 gpg-agent --daemon gpg-agent 27915 ...
-1
votes
2answers
184 views

shell: create Shortcut command (alias or function) for working with IP address as arguments

I am not sure if I performed the following illegal or true but what I need is - to create set of ready commands so if I need to use , for example to match IP address with 4 octet I can use the ...
0
votes
2answers
318 views

How to add a variable into a grep command

I'm running the following grep command var=`grep -n "keyword" /var/www/test/testfile.txt` This work just as expected but I need to insert the file name dynamically from a loop like so: var=`grep ...
2
votes
2answers
971 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 ...
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 ...
0
votes
3answers
2k views

Command does not execute in crontab while command itself works just fine

I have this script from Colin Johnson on Github - https://github.com/colinbjohnson/aws-missing-tools/tree/master/ec2-automate-backup It seems great. I have modified it to send email to myself every ...
0
votes
2answers
537 views

How to hide/masquerade password in script

I use the following script to change Open Directory (Apple's LDAP) passwords. I don't like leaving the actual password within the script -- is there any way to hide or masquerade this so the script ...
0
votes
4answers
143 views

Assigning environment variables for CRON

I have a .sh script that creates a .tar.gz file and transfer's it to a remote server using RSA keys for authentication. The script will run from terminal but it will not when I try to set it up as a ...
2
votes
3answers
172 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 ...
0
votes
1answer
163 views

How to make a Bash Script take user input for Changing a Password

The following command on OSX will change an Open Directory (Apple's LDAP) password. The $ is the prompt: $ dscl -u diradmin -P 'password' /LDAPv3/127.0.0.1 passwd /Users/username newpassword I ...
1
vote
2answers
180 views

Different behaviour of script locally and over ssh

I have a script on a server-A Script-A #!/bin/bash -l echo "script-A.sh" | change-environment.sh When I ssh onto server-A and execute it, it works fine. However, when I ssh user@server-A ...
0
votes
3answers
229 views

Files copying between servers by creation time

My bash scripting knowledge is very weak that's why I'm asking help here. What is the most effective bash script according to performance to find and copy files from one LINUX server to another using ...
0
votes
2answers
2k views

syntax error near unexpected token `then'

I created bash script wich works as Nagios plugin. Here is a part of it: 44 CURDUPLEX=`ethtool $IFACE|grep "Duplex"|cut -d ':' -f 2|xargs` 45 CURSPEED=`ethtool $IFACE|grep "Speed"|cut -d ':' -f ...
0
votes
3answers
181 views

How to join a variable number of lines

I have a file with Feature names and a variable number of usernames below: Feature1 user1 user2 Feature2 user3 I'd like to be able to move the usernames to the same line as the Feature name ...
-1
votes
1answer
307 views

linux + print message on the screen after login to linux machine

I have linux machine red-hat 5.1 I want to write ksh/bash script that perform the following Each time that someone login to the linux machine then he will get the following message on the screen ...
1
vote
1answer
339 views

Can't restart mysql from cron job

I have a problem where MySQL (running on Ubuntu 12.04 with all latest updates) dies after a few days so put this script into a cron job that runs as root every 60 seconds. Everything works except ...
1
vote
4answers
132 views

How to execute shell scrips without creating files

How is it possible to execute a shell script without creating a file? For example assume I have the following script (testscript): #!/bin/bash function run_free() { free -m } run_free I then of ...