Bash is the Bourne Again SHell, the successor to the classic Unix sh (shell).

learn more… | top users | synonyms (1)

0
votes
1answer
17 views

How do I run TomEE as a service on RHEL6?

cat /etc/passwd (last line): tomee:x:990:987::/home/tomee:/bin/false I need to make init.d script to run Tomcat EE like "service tomee start" So I have 2 problems: 1. How I can execute command ...
266
votes
11answers
330k views

How to determine if a bash variable is empty?

What is the best way to determine if a variable in bash is empty ("")? I have heard that it is recommended that I do if [ "x$variable" = "x" ] Is that the correct way? (there must be something more ...
1
vote
0answers
11 views

Trying to get pid from a script running as su -c

I am trying to get these scripts to work in an environment where the java application needs to run as user foobar no matter if it is started as root or foobar. So these are my modifications to the ...
1
vote
2answers
41 views

bash + how to hold shell scripts

Is it possible to hold/stop the bash script progress without to kill the process? ( by kill command ) or other command For example this script - install_linux_pkgs.bash , will install Linux pkgs ...
6
votes
2answers
275 views

How to execute a command for each file in a deep directory structure, recursively?

I have a deep directory structure, with a large number of files (about 1M). I'd like to execute a command against each. (In my case the files are pngs which I'd like to run optipng against.) I've ...
1
vote
7answers
8k views

linux command line: find a host's canonical hostname

what is the easiest way to get a host's canonical host name from linux's command line? If it matters, my shell is bash. CLARIFICATION: I want another host's canonical hostname, either by ip or by ...
6
votes
4answers
3k views

SSH from A through B to C, using private key on B

I'm looking for a simple way to SSH from my local machine, A, through a proxy, B, to a destination host, C. The private key that goes with the public key on C is on B, and I can't put that key on my ...
0
votes
1answer
26 views

SSH: How to get the list of servers that autocomplete when hitting tab after ssh?

When I tab complete after typing ssh, I get a list of servers that I can ssh into. How would I get that same list with a single command? The pseudo command would be: ssh --list-available-servers ...
1
vote
0answers
43 views

How to run x instances of a script parallel? [migrated]

I have script I'd always like to run 'x' instances parallel. The code looks a like that: for A in do for B in do (script1.sh $A $B;script2.sh $A $B) & done #B done #A The scripts ...
1
vote
4answers
40 views

test when directories are in sync using rsync

Is there any way to know from a bash script when a rsync command does not download anything (aka the folder is in sync)?, I've tried using the exit code, but is only different when an error happens. ...
0
votes
2answers
23 views

Running ssh/netcat in the background

I'm trying to run a network throughput test between an OS X and a Linux host. I'd like to be able to measure the sustained throughput from the Linux host to the OS X host over time. I'd like to wrap ...
0
votes
1answer
26 views

How to change time format to seconds in ps -p?

I wrote a rsync script which also checks for how long the process of the script has been running. This is the relevant part: time=$(ps -p $processid -o etime= | awk -F: '{print $2}') # number of ...
3
votes
1answer
50 views

get notification when systemd-monitored service enters failed state

I need to have network messages sent when a systemd service I have crashes or is hung (i.e., enters failed state; I monitor for hung by using WatchdogSec=). I noticed that newer systemd have ...
2
votes
0answers
38 views

How prevent users from running commands via dot slash for a directory? [migrated]

Does anyone know if it is possible to restrict execution of commands via dot slash notation for a directory? The environment is bash on Linux. For example, I have a directory /usr/local/app/bin. In ...
18
votes
2answers
15k views

Check if array is empty in Bash

I have an array which gets filled with different error messages as my script runs. I need a way to check if it is empty of not at the end of the script and take a specific action if it is. I have ...
0
votes
1answer
20 views

ssh session stuck after some time of iddleness

I'm using fedora 19 and bash 4.2.53(1)-release If I leave an ssh connection opened for some minutes and don't do anything with it, the terminal get stuck. Here's netstat's output: tcp 0 ...
11
votes
2answers
18k views

Adding lines to /etc/profile with puppet?

I use puppet to install a current JDK and tomcat. package { [ "openjdk-6-jdk", "openjdk-6-doc", "openjdk-6-jre", "tomcat6", "tomcat6-admin", "tomcat6-common", "tomcat6-docs", ...
3
votes
1answer
2k views

Linux- Permission denied?

I'm installing Neo4j server as a linux service, but when I install it, I get the following message: /sbin/insserv: Permission denied What is this? What should I do? I'm running everything with ...
0
votes
2answers
24 views

How to handle passwords in a script: in-memory VS on-file

I have a script that runs on a VPS in a cheap cloud provider. The scenario is: I trust my provider, but I prefer to make his life hard if he ever wants to steal my key. All the interested folders in ...
-1
votes
1answer
33 views

How can I visualize a file removing every type of comment if a file (including /* */)? [closed]

I have this small script to visualize config files without the comment lines: cat $1 | grep -Ev '[:blank]*#|^[:blank]*$' | pygmentize -g but it still shows some comments in some files when they have ...
6
votes
8answers
5k views

how to write a script that only acts on new log entries

I feel like this should be a simple thing but I am having a hard time figuring it out. I am trying to write a script that will monitor one of the apache log files and take some specific action. But ...
0
votes
0answers
19 views

How to pipe output from cat to cut [migrated]

I want to cat /proc/uptime into cut -f1 in a Bash script. I've tried; cat /proc/uptime | cut -f1 cat /proc/uptime > cut -f1 cut -f1 < cat /proc/uptime Do I need to use echo or something ...
1
vote
1answer
31 views

unexpected end of file error in script file

#!/bin/sh # Host = ############### Port = #### email_id="##################" email_sub="######" # if ping -q -c 5 $Host >/dev/null then result_host="Successful" else result_host="Not ...
1
vote
0answers
30 views

Find pid of long running bash script [closed]

I find myself in an interesting situation I can't think of an easy solution for. I started a long-running shell script that I can't stop or let die. I forgot to screen/tmux this script out or to ...
3
votes
0answers
48 views

can't run remote ssh command without heredoc [migrated]

I can't get this command to work: user@server:~: ssh otherserver bash -ic 'source .profile; some-aliased-command' Variations I tried user@server:~: ssh -t otherserver bash -ic 'source .profile; ...
5
votes
5answers
618 views

Hide the output of a shell command only on success?

Hiding the output of a shell command usually involves redirecting stderr and stdout. Is there any builtin facility or command which by default hides the output but on error dumps all the accumulated ...
2
votes
0answers
24 views

Timing of ps piped to grep [migrated]

So, this isn't a problem as such, just something i'm curious about. I'm using Linux Mint MATE which is branched off Debian. If i do ps afx | grep abcdefg i get 16599 pts/3 S+ 0:00 | ...
55
votes
5answers
47k views

How to run a command multiple times?

Is there a way to run a command (e.g. ps aux|grep someprocess) for n times? Something like: run -n 10 'ps aux|grep someprocess' I want to use it interactively, please do not post scripts. ...
38
votes
10answers
14k views

How can I run arbitrarily complex command using sudo over ssh?

I have a system that I can only log in to under my username (myuser), but I need to run commands as other user (scriptuser). So far, I have come up with the following to run the commands I need: ssh ...
1
vote
2answers
29 views

Bash script rsync --include-from fail

I have writted a bash script to backup folders and files from a machine to our backup server. My goal is to exclude all the files older than 6 months from this weekly backup. To do that, I used a find ...
1
vote
5answers
3k 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 ...
0
votes
0answers
12 views

expect: does “” (spawn_id exp70) match glob pattern [migrated]

I have written an expect script that works perfect for testing passwords on our network until it has looped through my list quite a bit, then the debug output shows that there is nothing to match. ...
1
vote
2answers
33 views

Automate pg_dump in a bash script

I am re-learning bash after years of not using it very much and need to figure out a way to automate pg_dump of a single database to a directory. Currently I manually ssh into the box, su to postgres ...
0
votes
0answers
42 views

Pipe ssh's output (stderr and stdout) to different commands [migrated]

I'm a writing script for some kind of backup involving ssh and rsync. Every time that script runs I redirect all output to a log file. To standardize the log-entries I wrote a log-function that adds a ...
0
votes
1answer
33 views

Using curl with cookies

I hope someone can help me out on this one. I have been trying this for a while now, with all sorts of variations and cannot seem to get this to work. I am trying to script a way to log in to ...
0
votes
2answers
51 views

Running a bash script via cronjob to restart a service

First of all. I don't know anything about bash scripting. second this is a very big problem on my side, and I don't have any idea what to do. Currently, I have this website. which was written in php. ...
2
votes
1answer
76 views

Strange filename encoding

I have a strange issue regarding a filename. Summary of the situation is: [username@xxx tmp]$ ll -rw-r--r--. 1 xxx xxx 42694 8. Jun 19:56 12287_KKL_Messegerät_EF_30.1.pdf -rw-r--r--. 1 xxx xxx 42694 ...
2
votes
1answer
1k views

Calculate average of every 5 samples with rrdtool or other languages

I want to make an average of 5 samples and calculate a single value: Current output - I put resolution of 5 minutes but receive 5 samples: $ rrdtool fetch file.rrd AVERAGE -r 300 --start 1200000000 ...
0
votes
1answer
33 views

sudo su not working correctly inside a bash script [duplicate]

I have a script to setup a machine that need to change to another user. Unfortunately, I get a "permission denied" after the su command. #!/bin/bash # script executed from /home/foo/ touch hi_foo cd ...
1
vote
0answers
47 views

Write file from string with tabs [migrated]

UPDATE: this may be a Windows pasting to Linux issue. The issue is not just observed with cat, but also echo. However, if I vi the file and paste into it, the tabs are preserved. I have a string ...
1
vote
3answers
1k views

Capture piped multiline grep output into a variable

I'm using Zabbix's zabbix_sender.sh script to push exception stack traces to my remote Zabbix monitoring server. zabbix_sender.sh requires a key and a value for any data that it sends. It can read ...
0
votes
1answer
24 views

Find difference in file encoding

I am sending email from the cmd with msmtp for that I do cat > test1 << EOF >From: "Tester" >test >EOF cat test1 | msmtp email@mail.com This works while: echo -e 'From: ...
2
votes
1answer
964 views

Alias doesn't work in script with #!/usr/bin/env php

I've some PHP scripts which are starting with #!/usr/bin/env php. The default interpreter is PHP 4.4, but the scripts need PHP 5.3, so I created an alias in ~/.bashrc: alias ...
1
vote
2answers
908 views

Problems Using WGET to transfer files from an FTP Server

I make use of wget to get files from an FTP server. I do this: wget ftp://username:Password@XXX.XXX.XX.XX/public_html/images/audiothumbs/* . After I download about a 1600 files, I get this error: ...
0
votes
1answer
1k views

Improper output in SSH session on OSX using FreeSSHd on Windows with cygwin bash/sh shell

I am testing out running an SSH server on a local Windows VM. I have installed FreeSSHd and set the command shell to "c:\cygwin\bin\sh --login -i" (bash as well) with "Use new console engine" ...
12
votes
6answers
4k views

How to use a custom .bashrc file on SSH login

I've found that with the new company I'm working with I often have to access linux servers with relatively short lifetimes. On each of these servers I have an account, but whenever a new one is ...
4
votes
3answers
277 views

exporting bashrc file over an ssh connection

I have my bashrc file set up to my liking.I usually work on a hardware that is plugged into a remote server.I ssh into that remote server.I would like my .bashrc to be run when I ssh into the remote ...
5
votes
2answers
2k views

`ssh foo “<command/>”` not loading remote aliases?

summary: Why does this fail $ ssh foo 'R --version | head -n 1' bash: R: command not found but this succeeds $ ssh foo 'grep -nHe 'bashrc' ~/.bash_profile' /home/me/.bash_profile:3:# source the ...
1
vote
2answers
900 views

Non-blocking bash redirection

Does anyone know how to redirect the output of a program, running from a bash script, to a named pipe IN NON BLOCKING MODE (having 'O_NONBLOCK' flag set)?
7
votes
4answers
5k views

chsh: PAM authentication failed

i want to change default shell env and run chsh -s /bin/zsh as root user, but a error message appeared: chsh: PAM authentication failed. i find this thread ...