Questions about bash only, as opposed to other Bourne/POSIX shells. For all Bourne/POSIX-style shells, use the /shell tag instead.

learn more… | top users | synonyms

1
vote
1answer
103 views

grep (/sed/awk) month range

I've looked around for solutions to this, but it's sort of difficult to search for the solution to such a specific problem (lot of words to put in Google). So, I have a file with data that looks like ...
2
votes
2answers
24 views

Modify background jobs and/or notify on job completion post-launch [duplicate]

I would like to be able to somehow modify a running command and/or get notified when a running command completes after it has been started. Normally, when I know a command is going to take a long ...
4
votes
2answers
73 views

How to make program help text automatically pipe through less?

Just now, dpkg --help spit out three pages of output in my face. I was maybe interested in the first ten lines, which show the general usage and most common arguments. I'd like that, whenever I run ...
1
vote
1answer
39 views

Script not running correctly on startup

I have a very simple script that echoes some stuff then starts a VNC Server. It works fine when I run it on the command line but when it runs on startup it gives some strange results. Here is my ...
-1
votes
1answer
36 views

Alias to create and cd into directory [duplicate]

How can I create a reliable alias or function that let me create and cd into one directory? I tried the following, but, as an example can't create directories with spaces. mcd () { mkdir $1 ...
2
votes
3answers
64 views

How to insert bash variables in awk?

How to insert bash variables in awk (for example i need to do in in some for loop - like this: in first iteration use awk to search string by first column, next by second column and so on with using ...
6
votes
1answer
64 views

stat: print time in “long-iso” format

For my script, I would like to have stat command to print time in a nice, human friendly, way: 2015-02-04 00:48:31. ls calls this format long-iso and it can be used like this: $ ls -lA ...
1
vote
1answer
61 views

script needs to add another loop

script which runs netstat -tulpun | grep -i port_from_the_list & takes the output for running the next command I need to run 2 command on all the server mentioned in the list. server: Jan port: ...
0
votes
2answers
91 views

arch linux systemd RTC clock script does not execute

I have rtc.service service in /etc/systemd/system: [Unit] Description=RTC Service [Install] WantedBy=multi-user.target [Service] Type=oneshot RemainAfterExit=yes ExecStart=/scripts/script_rtc.sh ...
2
votes
2answers
57 views

suppress stderr messages in a bash script

Consider the following (slightly silly) script name 'test1.sh': #/bin/bash # sleep 10 & echo sleep pid = $! pkill sleep When I run it, I get not only the output of the echo, but bash's ...
0
votes
1answer
43 views

Make does not work when invoked from a bash script

So i just asked a question : for loop over a list This works perfectly now and outputs what i need. Now i want to link this to a makefile which should be called per variable in my list like this: ...
0
votes
2answers
80 views

Convert input string to date in shell script

My shell script: #!/bin/bash echo "$1"; startd=$(date -d "$1" +"%Y%m%d"); echo "$startd"; My command: sudo ./test.sh "20151010" The output: 20151010 20150213 it printed todays date ...
3
votes
1answer
47 views

How do you get the first file in each subdirectory matching a list of file extensions?

How do you get the first file in each subdirectory matching a list of file extensions? My goal is to run a program on just any one of the files in a series of subdirectories. For example, below ...
0
votes
1answer
50 views

auto restart apache when high load average

My server always shut down when it reach a high load average. I have optimized my apache, mysql. but i cannot prevent sometime in a heavy traffic. So I try to write some shell to control load average. ...
1
vote
1answer
18 views

Comparing variables in arithmetic

Was wondering if someone can take the time to explain the following: I have a directory of files (PDF), which I place into an array. shopt -s nullglob # Set array ...
1
vote
1answer
60 views

How can subtract 2 floats which have been extracted from 2 other files with BASH [duplicate]

I'm trying to get the difference between two numbers which I have taken from two files. I think my code will make sense: I've tried to make it work by two different methods, didn't work. What I get ...
3
votes
2answers
68 views

Execute command after inotifywait established watches

Inside shell script (test.sh) I have inotifywait monitoring recursively some direcotry - "somedir": #!/bin/sh inotifywait -r -m -e close_write "somedir" | while read f; do echo "$f hi"; done When I ...
-1
votes
1answer
37 views

killall fails some time

Hi below is the script which is intended to kill all instances of the process "processName" but sometimes it is not able to kill the process and we see double instance of the same process how can I ...
2
votes
1answer
3k views

Screen in bash script

I am using a bash script and I need to create a screen, execute a specific command with a memory limit and detach the screen. I have been trying something similar: #!/bin/bash for i in 1 2 3 4 5 6 7 ...
0
votes
3answers
28 views

Error when trying to accept a directory path as a command line argument

I'm trying to accept a directory path as a command line argument in order to check recently changed files - not too sure if I'm doing it correctly: script=$scriptpath find . "$scriptpath" / -user ...
0
votes
3answers
43 views

call command with absolute path using bash variable

I'm using android sdk and I need to use the android command in my script, the file I need is in the following folder: /my_downloads/android-sdk/tools/android. I tried to do this in my bash script: ...
2
votes
1answer
66 views

How to print last login time?

I'd like to know how to set in .bashrc file to print the last login time of users when logging into another user in terminal. I do know that with who or last, but I'd like something a little more ...
2
votes
1answer
34 views

Rotate image if width is greater than a value (i.e in pixels)

I was trying to rotate few hundred images which have 7000px height in 1000+ images how to rotate them from bash.
7
votes
2answers
11k views

In a bash shell script, writing a for loop that iterates over string values

In bash, I know that it is possible to write a for loop in which some loop control variable i iterates over specified integers. For example, I can write a bash shell script that prints the integers ...
3
votes
4answers
3k views

How to capture error message from executed command?

I was tasked to create an automated server hardening script and one thing that they need is a report of all the output of each command executed. I want to store the error message inside a string and ...
1
vote
1answer
83 views

bash script problem when run from desktop launcher

I have a script which does the following: Connect via sshfs to a directory on a server Within that directory, there is an encrypted volume. Open it to the device mapper. Mount to a local directory ...
0
votes
3answers
216 views

How to concatenate a variable number of csv, removing their header rows?

I have a directory with several hundred csv files whose filenames start with two digits {01..84}. Several hundred >> 84, so obviously some filenames start with the same prefix. I wish to concatenate ...
6
votes
3answers
372 views

How to define a Bash function that can be used by different scripts

I have defined a bash function in my ~/.bashrc file. This allows me to use it in shell terminals. However, it does not seem to exist when I call it from within a script. How can I define a bash ...
0
votes
1answer
48 views

While loop stuck in infinite loop

I cannot figure out why this function gets stuck. What I am trying to do is create a folder from a predetermined start date up until the present month. Unfortunately it completes all the folder ...
7
votes
2answers
411 views

Bash - how to run a command after the previous finished? [duplicate]

Currently I have a script.sh file with the following content: #!/bin/bash wget -q http://exemple.com/page1.php; wget -q http://exemple.com/page2.php; wget -q http://exemple.com/page3.php; I want to ...
3
votes
3answers
1k views

Create and Delete Amazon EC2 Volumes using a shell script

I am using this following script which does a regular backup of volumes on Amazon AWS cloud service. It creates new snapshots of the volumes and should remove snapshots older than two days. It is ...
2
votes
2answers
167 views

Consecutive commands

Am I correct to assume that when ; joins two commands on a line, Bash always waits until the first command has exited before executing the second command? And similarly, in a shell script containing ...
0
votes
1answer
40 views

nvm command not available in bash script

I am trying to build a script in in which nvm and eventually node will get installed. I have installed nvm with cURL. I see the modifications in the .profile or .bashrc file (both work) and when ...
1
vote
1answer
28 views

Non-block poll from two pipes?

Here is what I want to do.. mkfifo infrequentlog frequentlog sort -m infrequentlog frequentlog > mylog funcA > infrequentlog funcB > frequentlog So that when monitor tail, I can see the ...
4
votes
6answers
6k views

CentOS | [root@hostname] does not show anymore?

For some reason I logged into my CentOS6 server and at the beginning of every line it normally shows [root@hostname]# Now it shows -bash-4.1# What does this mean? And how to I get it back to ...
10
votes
2answers
5k views

Why would anyone not set 'histappend' in bash?

After finding out what this shopt -s histappend means, it seems a very sane setting, and I'm surprised that it isn't default. Why would anyone want to wipe their history on each shell exit?
5
votes
1answer
61 views

Can someone explain how to use flock and file descriptors to lock a file and write to the locked file?

Bare with me as I am new to the flock tool and I haven't used file descriptors as far as I know. I have a bash script that makes a cURL request and writes the output to a file called resp.txt. I ...
1
vote
1answer
63 views

exec redirects in bash

I write a lot of non-interactive scripts where I would like all output to go to a log file and have nothing appear on-screen. To solve this, I've been using: #!/bin/bash exec &> logfile echo ...
2
votes
1answer
48 views

Supply the same filename as argument to two commands [duplicate]

On a git conflict, I can currently do: git diff path/to/some/file.txt ... after reviewing the diff, usually I want to do: git checkout --theirs path/to/some/file.txt && git add ...
1
vote
1answer
44 views

How to use bash shell for gnuplot to show Greek letter?

I want to write a bash shell for gnuplot to produce figures automatically. But my figure includes Greek letters inside. I have known their ASCII number, how can I show them correctly in figures after ...
0
votes
2answers
9 views

Manually executing a CRON - Confused about params

I have this code snippet: $CUSER=tim $APPDIR=/var/www/testing $APPVENV=/var/www/testing/ven cat > $APPDIR/cronfile << EOF PWD=$APPDIR/$CUSER PATH=$APPVENV/bin:\$PATH 0 2 * * * testapp search ...
0
votes
1answer
31 views

What does `line 19: 12364 Killed` mean in crontab error message?

I got a daily crontab task: 50 1 * * * sh /my_path/daily_task.sh > /tmp/zen_log 2>&1 This daily_task shell script will run some python scripts and produce a data file. And it fails for ...
5
votes
3answers
363 views

Use bash's read builtin without a while loop

I'm used to bash's builtin read function in while loops, e.g.: echo "0 1 1 1 1 2 2 3" |\ while read A B; do echo $A + $B | bc; done I've been working on some make project, and ...
57
votes
8answers
60k views

How to add a newline to the end of a file?

Using version control systems I get annoyed at the noise when the diff says No newline at end of file. So I was wondering: How to add a newline at the end of a file to get rid off those messages?
3
votes
2answers
36 views

How can I catch a command exit code for later, in a Makefile?

I have a makefile, with a test suite target, like so: rcheck: foo This shows the output from the foo command on stdout, and returns an exit code from foo which is handled by make as normal. ...
1
vote
0answers
32 views

A way to distinguish between interleaved output from two background processes

If I have two backgrounded processes that produce input to STDOUT or STDERR (e.g., two installation scripts), is there an easy way to make these two output streams distinguishable? I guess I can pipe ...
0
votes
3answers
158 views

Bash ping script file for checking host availability

I am trying to write a bash script in a file that would, when run start pinging a host until it becomes available, when the host becomes reachable it runs a command and stops executing, i tried ...
2
votes
2answers
60 views

Custom bash 'context' when running from FISH

First of all, I'm on OSX10. My default shell is BASH, which I have set up (through .profile and .bashrc) to automatically run the FISH shell when I open my terminal emulator. This allows me to set up ...
3
votes
3answers
564 views

Determine maximum column length for every column in a simplified csv-file (one line per row)

To determine the maximum length of each column in a comma-separated csv-file I hacked together a bash-script. When I ran it on a linux system it produced the correct output, but I need it to run on OS ...
6
votes
2answers
386 views

How do I find number of vertical lines available in the terminal?

I'm writing a script which shows the git log for a directory when I cd into it. Such a log can be overwhelming, containing hundreds of lines. So far I have been limiting that to a hard-coded 20 lines ...