Bash scripting is making scripts in the Bash shell language.

learn more… | top users | synonyms

1
vote
1answer
21 views

How to use github via HTTPS?

I'm trying with this to create a simple static HTML website using github. I already created a repository named: "GITHUBUSERNAMEANDREPO". #!/bin/bash git config --global user.name ...
0
votes
0answers
12 views

bash behavior on sigterm

Have a script as below: #!/bin/bash # # run this script. don't run it if it's already running. # PIDFILE=/tmp/script.pid LOGFILE=script.log if [[ -f $PIDFILE ]]; then echo "$PIDFILE exists. ...
1
vote
2answers
47 views

How to redirect output to file that has slash in name

I want to create a file named ./https://www.example.com, but the following doesn't work: [ ~]$ URL="https://www.example.com" [ ~]$ echo "Hello!" >"$URL" bash: https://www.example.com: No such file ...
-1
votes
0answers
12 views

Read multiple inputs and store in a array, then print the values from that array in shell script [on hold]

Read multiple inputs then store in a array or variables, then print the values from that array/variables in shell script read -p " Enter no. of users : " no_user if [ $no_user -gt 1 ]; ...
0
votes
0answers
14 views

“Failed to start SYSV” when starting self-made service

I'm trying to set up a service, on root, that will automatically start monetdb database after system startup because monetdb doesn't provide such mechanism. I've created /etc/init.d/monetdb script ...
0
votes
0answers
29 views

Linux script, mobile responsive [on hold]

last post seems to have gone astray so.. I am hoping someone could tell me/give me a script that will check if a list of web addresses are mobile responsive. This would save a lot of time against ...
0
votes
2answers
15 views

Using MV to rename large amount of files using a script

I'm writing a bash-script to rename a large amount of files, using mv. Original filename File001.txt New filename file-new-001.doc I can change the suffix but i do not know, how to insert the ...
0
votes
1answer
63 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
0answers
10 views

Remove orphaned data without corresponding torrents in the rtorrent's list

I use rtorrent with a plenty of frontends like ruTorrent and Transdroid. Often, when I try to delete both the torrent and data through these frontends, the torrent is removed from the list but the ...
1
vote
2answers
28 views

Given key-value content, how do I group values by key and sort by value?

I've the following sample input format (file or stdin): key1: 1 key2: 2 key3: 3 key1: 4 key2: 5 key3: 6 Is there any few-liner which can group values based on the key and then sort? Expected ...
2
votes
2answers
22 views

GNU sort cyrillic lines ignoring the case

I have got a file in UTF-8 with lines of latin or cyrillic letters. I'm trying to sort it, ignoring the case. I have tried LC_ALL="ru" sort --ignore-case in.txt but still got cyrillic lines in ...
2
votes
1answer
135 views

How to make a bash script that names files with today's date

I'm trying to make a script to back up my we servers, but I have very limited knowledge with bash scripting. I want the script to name the backup file ht-"today's date". How would I go about doing ...
1
vote
3answers
2k views

How to define alias for command which will be available in shell script?

Here is a part of my .bashrc alias my_command="my_command -1 -2 -3" and its my shell script #!/bin/sh my_command blah blah blah It occurs into error ./aa: line 2: my_command: command not found ...
0
votes
4answers
62 views

While loop Bash script that outputs how many users use a certain shell

So I am stuck on trying to create a bash script while loop function that takes the input from /etc/passwd and outputs how many of users use bash, nolongin, csh, and ksh. I believe I am supposed to ...
0
votes
1answer
94 views

Why am i getting execute binary file error?

i am getting following email every 10 min. as I own the VPS. I am not expert in linux and am learning to manage linux servers. Please help me why am i getting these emails and how to stop them or how ...
1
vote
1answer
37 views

How to daemonize a bash script only if --daemon flag is given?

I have my script.sh and want to run it with ./script.sh or ./script.sh --daemon, having it remain in the foreground unless the --daemon flag is given, in which case it should detach and go into the ...
0
votes
1answer
17 views

Unix/linux shell scripting floating point division

I have to divide two floating point values and store it in variable. My code below v_missedvol=4003.03 v_allvolume=3003.03 v_vol_temp= $(echo "$v_missedvol / $v_allvolume" | bc -l ) the result ...
2
votes
2answers
1k views

Shell script to rename multiple files from their parent folders name

I have a file structure like this: 00000010 000000001.file1 000000001.file2 00000020 00000003.file1 00000003.file2 00000003.file3 ... So there are folders with 8-digit names containing one ...
1
vote
1answer
13 views

Cut lies if delimeter doesn’t exist

For example: $ cut -d ' ' -f 2- <<< "example" example Why does cut lie to me telling me that “example” is the second delimeter and on. I want it to print "" since there is no second ...
0
votes
2answers
27 views

Forcing a process to background from bash script

I'm trying to crfeate a bash script that - amongst other things starts sunwait: /root/bin/sunwait sun up -0:00:00 54.453158N 11.013071E; mycommand & Sunwait is a binary that will wait for ...
0
votes
1answer
18 views

Dealing with a string as file input for a program within bash script

Say I have tool X that accepts only files as input, is there any way to pass input to X as a string without having to write it to file then reading it within a bash script?
0
votes
3answers
34 views

Is there an automatic way to add group read permissions to “nohup.out” when “nohup” is run?

I run my Java code from bash script using a command like this: exec nohup "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" com.myClass "$@" & Which creates the output file nohup.out and this ...
1
vote
3answers
36 views

Looping until background process is done (with `jobs`) doesn't work in script

I'm trying to loop until a background process (launched earlier in the script) is complete. An easily reproducible test case is: ping -c 10 localhost &>/dev/null & On the command line, I ...
0
votes
0answers
18 views

shell script to generate a log file for VM Backups

we are using PHD virtual backup to trigger backups for VMs and now i want to generate a report of all VMs in a file consisting of VM Name, Date and Backup Time and mail it to my ID at particular ...
0
votes
1answer
146 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 ...
0
votes
1answer
44 views

How to execute multi-line ssh command stored in a variable

Context: I'm trying to execute a bunch of commands on a remote machine that I cannot access directly - I first have to ssh into a gateway machine, then ssh from there and run the commands. Basically ...
1
vote
1answer
53 views

Bash: better way to output to both console and output file than tee?

What I need to display is a log refreshing periodically. It's a block of about 10 lines of text. I'm using |tee and it works right now. However, the performance is less satisfying. It waits a while ...
0
votes
0answers
37 views

+Merlin FW / Port Forward via IPtables?

I have 2 WiFi Thermostats, Heatmiser, that i can control remotely, from LAN without issues, but only one from WAN. The thermo have a fixed port that cannot be changed and there is an App thet can be ...
0
votes
1answer
31 views

$RANDOM in script vs. on command line

I think I found a really odd bug in Bash's random number generator ($RANDOM). Showing is easier than telling, so here's what happens: The goal is to get random digits. If I execute this, I get 20 ...
0
votes
0answers
23 views

Having trouble building Vagrant bash script

I'm trying to set up a bash script provision to help build my virtual machine with Vagrant, but I'm clearly doing something wrong. Unfortunately the Vagrant docs don't provide any examples more ...
0
votes
0answers
12 views

Curl should be quit but it returns ever something

I tried to login to a website using curl in a bash-script. It is possible to login to the site quiently using this: curl -d "username=$username&passwd=$passwd" -c $cookiefile ...
-1
votes
2answers
50 views

simple loop not working

A simple script now="$(date +'%d_%m_%Y')" path="/var/www/vitalii/backups" sites=("site1.ru site2.ru site3.ru") for i in ${sites[*]} do echo "$path/$i" #tar -cvzf $path/$i_${now}.tgz ...
1
vote
1answer
71 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 ...
0
votes
0answers
24 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
66 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
1answer
23 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 ...
1
vote
0answers
17 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
1answer
40 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 ...
1
vote
2answers
668 views

extract characters between first and second underscores of filenames and count such files in linux folder

I would like to extract characters between first and second underscores of filenames in a folder and count such type of files present in it. The folder contains files in a particular format such as : ...
12
votes
2answers
451 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 $ ...
5
votes
5answers
1k views

How to move all sibling folders into one folder?

I apologize that this seems like such a dumb question, but I can't afford to screw it up. I have a bunch of folders like so: /users/me/foo/oops1 /users/me/foo/oops2 ...
0
votes
3answers
2k views

FTP from bash script running from cron not working

I have a script that is run by cron to create backup of a MySQL database and some files. After creating a tar ball and encrypting it with openSSH I have to put it on a remote ftp server. Following is ...
0
votes
4answers
105 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
33 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
46 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
80 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 ...
1
vote
1answer
48 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 ...
0
votes
2answers
43 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 ...
2
votes
1answer
1k 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 ...
10
votes
1answer
887 views

why doesn't a bash while loop exit when piping to terminated subcommand?

Why doesn't the command below exit? Rather than exit, the loop runs indefinitely. While I discovered this behavior using a more complex setup, the simplest form of the command reduces to the ...