Bash scripting is making scripts in the Bash shell language.

learn more… | top users | synonyms

0
votes
0answers
16 views

Spawn new consoles from script and get back to the main console instance

The goal is to use a script to launch and execute a command in n separate window terminal: (I use lxterminal) It works when I copy/pase the following block of commands, It executes each lines ...
0
votes
0answers
24 views

how to grep exact pattern

I’ve tried several grep / egrep ideas with different options but none worked here. I’m trying to grep exact match of the pattern I’m looking in a log. For example I want only a pattern “ERROR” to get ...
0
votes
0answers
8 views

Curl should be quit but it returns ever anything

I tried to login to a website using curl in a bash-script. The script should first send the login data with -d and get the cookie through -c, so that i can use it secondly to login with -b. My ...
0
votes
0answers
13 views

Grep from Log & Calculate then alert

I have a log file, which has the below lines in it. I need a bash script, which takes the values in Bold (4092.1M / 20.1G) & do the math & then alert from Zabbix [Eden: ...
0
votes
0answers
44 views

Require bash script to be run with sudo (not as root user)?

I want to require a bash script to be run as the current user with sudo, but prevent it from being run if it was executed as the root user directly. This is because I'm doing some setup actions for ...
1
vote
0answers
24 views

[: -gt: unary operator expected

I have a code, which gives [: -gt: unary operator expected, when the value is empty. Can anyone please suggest or correct me where I'm wrong ? if [ -e $POSFile ]; then # Read last Position ...
11
votes
3answers
434 views

Determine type of device Bash script is being executed on (laptop or desktop)?

Is there any reliable way to determine (programmatically) from within a bash script if it is being executed on a laptop or a desktop computer? I could obviously just prompt the user to ask them, but ...
0
votes
1answer
22 views

BASH associative array rearrange keys

I am running into a weird issue with associative arrays in bash. I have the following files in a directory: ls -lart drwxr-xr-x. 3 root root 4096 Feb 9 11:14 .. -rw-r--r-- 1 root root 3275 Feb 9 ...
0
votes
1answer
15 views

How to detect ips using nmap?

I am currently working on demonstrating Man in middle Attack foe which I am using my phone as a Victim and my PC running ubuntu 14.04LTS as attacker. I am using nmap to ping my phone to check if its ...
12
votes
2answers
405 views

Difference when using backticks in double quotes and single quotes in Bash

Why to the following two executions differ in output? (I need double quotes for variables in my eventual command) $ sudo su -c "echo `cat /root/root_file`" cat: /root/root_file: Permission denied $ ...
0
votes
0answers
37 views

Bash function only works when password manually input

At work I have to run the following function everyday. The function works fine when I am prompted for the password. However, I tried to hardcode my password so that I don't have to enter it in each ...
0
votes
4answers
81 views

How do I DELETE a comma and a space from a numeric string using a bash script

Folks, I have asked this question 5 times on here and have received 5 separate bits of code from super users that have all *failed. Problem: I have stock information being brought back into a txt ...
0
votes
1answer
28 views

Bash script failure

I have this script. It works fine on one of system but it's giving some error on another machine: 1 #!/bin/bash 2 EXEC_DIR=`dirname ${0}` 3 source ${EXEC_DIR}/config.sh 4 5 ...
0
votes
1answer
42 views

I want to append the name of the file on the top of that file using bash script

I want to add void mainfunction() on the top of a file. I am reading the actual name of the file from another file and the name of the main function from another file. I was using: sed -i 1i void ...
1
vote
1answer
50 views

Bash loop through all directories within a directory and if find any instance of string in each directories specific file do this

I have a service that utilizes a unique user specified port for remote connections. I install multiple instances of this service and wrote a bash script to automate the installs. My installer has a ...
0
votes
2answers
39 views

bash: How to use a quoted argument in select

From a command I get some arguments that I want to offer to the user with the select statement from bash in a shell script. The arguments supplied by the command may contain spaces and are therefore ...
1
vote
1answer
40 views

How can I use the pipeline output from different commands inside a custom bash script?

I have this simple script: #!/bin/bash # This command removes the last "\n" (line feed) character from the file specified as parameter # # Params: # $1 [FILE_NAME] - the name of the file to trim if ...
1
vote
1answer
327 views

How to update bash on Mac OS X Yosemite

Just trying to learn bash scripting a little. My old bash version: Bash version 3.2.53(1)-release... I've updated my bash on mac os x yosemite with homebrew: brew update brew install bash Then ...
1
vote
1answer
132 views

Bash script to execute jar with parameters and using file path variables

I am trying to run the following bash script and it gives me the following error #!/bin/bash -x jars= $HOME/SelGridProto/selserversidedjars java -jar $jars/selenium-server-standalone-2.44.0.jar ...
2
votes
1answer
34 views

Check for Free Space on Linux, email if critical

I just finished dealing with a server which had run out of space, and would like to setup monitoring on it now, to prevent it going critical in the future. What I would like is to get an email sent ...
3
votes
2answers
52 views

opening several terminals at once

In my dev environment, I sometimes need several terminals to be open, each running its own script/ a server (rails, django, redis, mongo, consoles, etc) How can I create some shortcut that will open ...
0
votes
1answer
39 views

Launch a bash sub-shell and expect a command

From a shell script, how can I launch a bash sub-shell for the user & wait for the user to type exit at the bash sub-shell prompt? I tried bash -c expect -c 'expect "exit" {send "Exiting\n"}'; ...
1
vote
2answers
27 views

Is there a way to pass arguments via pipe on bash?

Is there any way to pass arguments via pipe on bash? something like: echo value1 value2 | mkdir -p ./$1/$2 The line above would create the directories ./value1/value2 If this is not possible I ...
0
votes
1answer
16 views

Move spam emails from directory - bash script

I am trying to write bash script wich can cleanup my whoole server from spam emails that already are present in my client's folders. I would need this script to do, Check recursively directory ...
0
votes
1answer
33 views

Bash on android [closed]

I have a rooted sony z2 smartphone and I'm able to run sh scripts, I also have busybox installed but I'm unable to work out how to run bash scripts, I've tried ls -l /bin/bash from terminal and get ...
0
votes
1answer
31 views

Without eval command does not run correctly

just something that i can't seem to figure it out. Begginner bash scripter here I wrote a script to accept command line parameters that are later passed to maven Here's is the working version of the ...
0
votes
1answer
18 views

i need to pass a string of an output file to a variable so as i can use it globally all over my script [closed]

sample output RETENTION_INTERVAL ------------------ 10080 I need to pass the numeric value "10080" from the output file to a variable .The condition should validate value and ...
0
votes
0answers
8 views

avoid sigstop in script bash

alias notesave=' cwd=$(pwd) && cd ~/Desktop/Notes && git add * && git commit -a -q -m "-_\@" && git push -q origin master && echo "DONE!" && cd $cwd' ...
0
votes
0answers
21 views

Bash script monitor file modification after its closed

It has already been asked here and I have found the solution for the first part of my question. So for the moment I have a bash script (script1) where I evaluate the sha1sum of a specific file ...
0
votes
1answer
23 views

'hhighlighter' wrapper script saying command not found

I have gotten the wrapper script 'hhighlighter' from https://github.com/paoloantinori/hhighlighter which colors anything you want in stdout. I followed the instructions about installing ack-grep, ...
0
votes
1answer
20 views

Append text at the end of a specific line

I have a file with multiple lines. What I am trying to accomplish is add a string at the end of a commando. I have a script that installs a tool automatically. Now some things have changes in the ...
1
vote
1answer
65 views

Format terminal output to show apt-get upgrade errors in RED

I have a VERY simple bash script written for my Kali Linux distro so I don't have to run apt-get update, apt-get upgrade, apt-get dist-upgrade, apt-get autoclean, and apt-get autoremove every time I ...
2
votes
3answers
118 views

How to open one GNU screen tab for each directory in a list

I have the following script - it sort of works. #!/bin/bash ... define plugins, etc for plugin in ${plugins[@]}; do screen -t $plugin done Want I want it to do open gnu-screen and for ...
0
votes
0answers
66 views

Monitoring xinput keycodes in bash

So basically, what I'm trying to do is use the xinput command to watch for keyboard input in the background for a bash script to toggle things. I would like to ideally monitor multiple different ...
1
vote
1answer
70 views

Executing PHP file from command line with dynamic parameters

I need to run one script which will take one date as an argument. It is configured using cron to run on a daily basis, but I need to run it for a time range now. The issue is that this will fetch all ...
0
votes
2answers
54 views

Use “read” in Bash script with a standard answer

How can I use read with something as standard response, which the user can change though? (a default answer)
1
vote
1answer
14 views

Homebrew script to reinstall formulas

I'd like to develop a bash script to capture the currently installed Homebrew formula, then be able to reinstall these formulas in the event that I need to reinstall my OS. I'm hoping to combine ...
2
votes
1answer
23 views

Unset bash variables referring to non-existent directories

I have a file which is sourced by an application, adding relevant directories to $PATH and $LD_LIBRARY_PATH. This is fine, but it results in somewhat excessive pollution of the $PATH and ...
0
votes
1answer
91 views

Detect window's fullscreen status on Linux?

So basically, I'm trying to write a watchdog script, that checks window titles against a list stored in a file. If the window is fullscreen, the script should do nothing and move on. If the window is ...
0
votes
1answer
44 views

Passing different set of arguments to the different commands in a linux bash script

I am writing a bash script foo.sh that runs too commands bar with first input argument, and baz with the second argument: #! /bin/bash bar "$1" baz "$2" Now I want to make foo.sh more flexible, ...
0
votes
2answers
472 views

Update a sqlite database while select into a while loop

There is a bash script that will do "some magic"™ to files which will be referenced to a sqlite database and after doing "some magic"™ the database should be updated. Here are the simplified code ...
0
votes
1answer
35 views

Unexpected result from sort command of linux bash

I have a file foo.txt with this content: chr1 15 chr11 5 chr11 8 chr1 7 chr2 23 chr1 35 I tried to sort it first according to the first column, and then according to the second ...
2
votes
1answer
38 views

How to get status code of program piped to linux dialog command

I am trying to use Linux dialog to prepare simple installer for Ubuntu. The actual command is: dpkg -i package.deb 2>&1 | dialog --programbox "Installing..." 10 100 I want dialog to ...
1
vote
2answers
130 views

Restarting process in CentOS if server restarts

I have a VPS with some Java applications (made with "Play Framework") running on ports 9000, 9001, 9002 and 9003. VPS Provider (iPage) happens to reboot servers unexpectedly from time to time, leaving ...
0
votes
0answers
18 views

Is “Lynx: can't access startfile” normal when I'm looking for broken links? I'm kinda desperate

I'm doing a script in bash for checking broken links, is it normal that the dialogue "Lynx: Can't access startfile" appears when I run the script? This is my code so far: #!/bin/bash ...
0
votes
1answer
66 views

`if` statement with stdout && passing xargs through pipe

Say I have a list.txt of files I want to check. cat list.txt and for each file, I want to perform an action cat list.txt | xargs -I {} touch {} But depending on the outcome of the action, I want ...
0
votes
1answer
49 views

Does Killing A Bash Process Affect Children Processes [duplicate]

The Scenario I'm automating backups via a bash script. The script is executed via cron. The script archives directories recursively using tar, and then rsync's them to the remote host. Here is a ...
0
votes
2answers
33 views

Write PID To File On Bash Execution

I'm executing a bash script via cron. I want to write the process id (PID) of the script to a /tmp/ file for reference, in case I need to kill it later on (this script can take 6 - 10 hours to ...
2
votes
1answer
110 views

Unable to Create Files In Directory

There are lot of these kinds of questions on superuser, so I'll try and keep this quick by telling you what it's not: There is no application involved here. Just a user and a filesystem. I can login ...
2
votes
1answer
66 views

Creating directory name from file name - strip out non alpha numeric characters and make lower case

I am able to create a directory based on the name of a file. I am running into a wall if the text has spaces or non alpha numeric characters. I would like to strip out those non alpha numeric ...