Bash scripting is making scripts in the Bash shell language.

learn more… | top users | synonyms

4
votes
6answers
2k views

What is the simplest way to remove lines from one file matched with lines from another file?

What's the simplest way to remove lines from one file matched with lines from another file? For example, if I have the following files: file1.csv: u2@domain.com file2.csv: 1,u1@domain.com,...
0
votes
3answers
37 views

move all files on directory to new subdirectory in same directory

Please how to move all files on directory to new subdirectory in same directory ? Like this: /volume1/TEST/file1.jpg to /Volume1/TEST/_NEW_FOLDER/file.jpg /volume1/TEST2/file2.bmp to /Volume1/...
0
votes
1answer
8 views

Strange behaviour when sorting IP addresses. (sort -nu)

I just tried to |sort -nu (numeric & unique) a list of ~30 or so IP addresses and noticed that in addition to culling duplicate lines, it's treating similar lines (i.e. addresses with the same ...
0
votes
2answers
37 views

bash script: 'while read' loop through lines in text file losing characters. ffmpeg line to blame?

I am looping through a text file, using 'while read'. I read three variables from each line - two filenames and a decimal number. I know that this works in a vanilla setup (loop, read line, echo line, ...
0
votes
1answer
26 views

Scripting with tmux?

Can I script several bash/sh instructions to open and run in separate tmux panes? I have about 5 or so different commands that need to be executed simultaneously or consecutively. I usually type ...
1
vote
1answer
24 views

Bash completion: filter out backup (~) files

I would like bash to filter out backup files, with a name ending in ~ (tilde), when auto-completing filenames. I have written a script to set this when using vim (I have very little experience with ...
0
votes
2answers
14 views

Monitor log live for error. If error = rerun command and restart log monitoring, if not found = keep monitoring forever

A process in a bash script I'm developing often fails quietly (it keeps running with no error code, but it writes the error in its log file). As soon as the error appears in the log file I want the ...
1
vote
1answer
30 views

Bash Script, Striping out newline characters in variable

Still getting the hang of bash scripting... I have a function that resizes images and calculates how much to scale it based on the file size. I need to pass this percentage as an argument to the ...
-1
votes
1answer
47 views

Why does this “find” command scan all directories?

I only want to recursively scan Documents and not leave that "parent" folder. My script scans recursively my entire file system, and I am not sure what element of this script is causing that to occur....
8
votes
2answers
25k views

How can I compare a variable to a text string, rather than integer, in an if/else statement?

In the process of writing a shell script, I ran into an issue with the following if/else statement that falls somewhere in the middle of the script: if [ $act -eq "add" ] then read - "add or ...
0
votes
1answer
18 views

regexp search and replace for bash variables

A number of my bash scripts need tidying up before sending them round. One of the thing I would like to do is to use curly braces for all variable names. So everywhere it says $PWD should be changed ...
0
votes
1answer
23 views

What is the difference between \e[38;5;175m and \[\e[38;5;175m\] as it relates to bash colors?

I have been trying to learn how to customize my shell and I came across two different ways of specifying colors in the Bash shell. They both seem to accomplish the same goal and I am not sure what (if ...
0
votes
1answer
33 views

How to pipe binary stdout to a compressed tls connection?

Not so long ago, I could use : cat somefile.txt | openssl s_client -connect server:port -quiet -comp However, this command doesn’t work, even with-ign_eof: $ cat somefile.bmp | openssl s_client -...
0
votes
1answer
12 views

lost virtualenv display to the left of bash prompt

I added thy Holy prompt to display my current branch so I never push to master. We all use it and it works, but I am no-longer seeing what virtualenv I'm using at the moment, which is a hassle. Based ...
0
votes
1answer
49 views

Run script without typing sh on Android

I wanna run my script which is located in system/bin and permissions is 755. With sh myscript there is no problem but myscipt or ./myscript doesn't work even if the pwd output is /system/bin. On ...
0
votes
2answers
70 views

Replace backslash(“\”) with forward slash(“/”) in a variable in bash

I want to replace backslash(\) with forward slash(/) in a variable in bash. I tried it like this, but it doesn't work: home_mf = ${home//(\)//(/)} For example, I would like \a\b\c -> /a/b/c
0
votes
2answers
41 views

'hhighlighter' wrapper script saying command not found [closed]

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
0answers
20 views

Lua variable as a shell command

Hii aLL Im using Awesome Wm and i want to set a shell command as a variable on my rc.lua i look in Internet and i found this : SHell Command : $ ip link | grep "[1-9] :en" | cut -d ":" -f2 | awk '{...
1
vote
0answers
23 views

How to find processes which uses the most RAM in last X seconds?

Could you please help me to sort this out? I'm trying to write a bash script which will monitor ram usage (not only ram but cpu and network as well) and show me 3 processes which use the most ram in ...
1
vote
3answers
84 views

Outputting less into a file

while on bash, i tried to delete the 3 last columns of a file using: head -n -3 file > file but the file comes out empty. I can walkaround it but I would like to know what causes that. Thanks a ...
1
vote
1answer
22 views

Bash: Is it possible to declare each list item on a new line?

Example: You normally list values in a horizontal layout for var in 0 1 2 3 4 5 6 7 8 9 do echo $var done It would be nice for version control and readability purposes to enter each list item on ...
0
votes
2answers
44 views

Why the simplest Shell-Script isn't working?

I want hide the path in the Terminal and for that reason I typed: export PS1='> ' command which I found online with positive result. I thought to make it to a shell-script in order to not type ...
0
votes
2answers
19 views

running chained bash function commands in background

I am attempting to call port() { fuser -k $1/tcp; python manage.py runserver $1 ;} runproject() { cd $HOME/projects/$1 ; workon $1 ; port $2 & ; sleep 3 ; google-chrome 127.0.0.1:$2 ;} (port is ...
13
votes
5answers
12k views

How to truncate file by lines?

I have a large number of file, some of which are very long. I would like to truncate them to a certain size if they are larger by removing the end of the file. But I only want to remove whole lines. ...
0
votes
2answers
26 views

Evaluate each environment variable and set it back in ubuntu

I'm trying to write a shell script which reads all the environment variables, evaluate them for included env. variable with in them and re-export after evaluvation. Example - I've an environment ...
0
votes
1answer
15 views

Is there a native alternative to the `watch` command; for Darwin/OS X

I have a script that I'm trying to port from Linux to Darwin/OS X. The Linux version currently depends on the watch command, which doesn't appear to be installed on Darwin/OS X by default. What's the ...
15
votes
3answers
10k 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 ...
0
votes
1answer
25 views

Can I set a process name for my tomcats on CentOS ?

I have several tomcats running on my centos. If I try "top", all of them are shown as "java" . Is there anyway, such as changing the catalin.sh, that I can make each of the tomcat has its own name ...
1
vote
2answers
223 views

How to use Bash script to find .mov files recursively and convert them to .mp4 using ffmpeg

I'm working on a Mac system in a video company where I have to clean up a lot of folders and subfolders containing large intermediate video files. So I've been looking for a way to batch convert ...
0
votes
1answer
54 views

Shutdown a linux computer depending on the battery level

Is there a way to shutdown a linux-based computer when the battery charge drops below a certain level? I have searched through the shutdown and poweroff manuals but found nothing relevant.
2
votes
1answer
31 views

How to avoid terminal to scroll down to last message in bash?

I write a bash script that run some other commands in new terminal: #!/bin/bash # Sample script gnome-terminal --title="blah blah" -x bash -c ffmpeg -i udp://239.1.2.1:60001?fifo_size=50000000 -...
0
votes
1answer
59 views

Dictionary attack in Bash with cURL

I'm fairly new to Bash, but this is a script I've been working on for the past few days. It's meant to run a dictionary attack on an HTTP-POST login for a website, by reading the time module and ...
1
vote
2answers
15 views

If Statement not evaluating as expected. Am I setting up my variables incorrectly?

I am trying to create a command that will allow me to check websites for specific words. I used \ at the end of the line to wrap it to the next, (not sure if I used those correctly here) these ...
0
votes
0answers
3 views

Is it possible to download the document from a typo3 CMS?

I have access to a typo3 CMS. The CMS displays documents in a viewer with tiled images at several zoom levels. The CMS also allows a download via a munged up PDF. By this I mean what is visible in ...
-2
votes
3answers
287 views

How can I write a bash function that checks if an integer is even or not?

How can I write a shell predicate function event that takes an integer argument and tests if it's even or not?
0
votes
1answer
57 views

Bash loop for adding --exclude list to tar

I have a bash script I made to encrypt/decrypt using GPG and tar. Right now I have my --exclude hard coded into the script, but I'd like to make it a bit more dynamic and add the items to exclude as ...
0
votes
0answers
19 views

calculate avg time for 3 person time in linux

how can i show 3 person's average sum in linux? For example, let the times for dough be 1,2,3,4,5 seconds delta be 5,6,7,8,9 amanada be 7,4,5,6,7 in bash script for all 3 users
0
votes
2answers
90 views

using sed in BASH script: replace text with info from system variables (hostname and date)

I want to use a bash script to run a backup and then send me an email using ssmtp. I am trying to make a generic script that I can reuse across different Linux machines. Below is a snippet of the ...
0
votes
1answer
28 views

My bash script's if / then check is always evaluating to true

I was trying to write a bash script to handle a conditional switch, and it kept evaluating to true every time. So, I stripped it down to this, and I was getting the same behavior of it always echoing ...
1
vote
1answer
26 views

Bash: return all the characters between the nth occurence of two different strings within a string

In a bash script (on Ubuntu 14.04) I'm running the command: WP055="$(wget -qO - http://alerts.weather.gov/cap/wwaatmget.php?x=CAZ055&y=1)" Within the WP055 variable string there will be an ...
3
votes
1answer
124 views

Confused about jq parser

I'm trying to use jq parser in my bash scripts and I'm confused about how it works, could someone explain what am I doing wrong? Here is the original file from the external service and I need to get ...
0
votes
0answers
45 views

Need help on how to create a Youtube Automatic Artist Discography List Generator and use this bash script to play it

Example: #FrankSinatra <-- based on youtube automatic generator "Top Tracks", then passing that list to this bash script player (listed below) randomly or not, could also accept more artists, ...
1
vote
2answers
112 views

Running script that has sudo commands with sudoers

I wrote a script that helps clean up my downloads and anime, but it won't run without root. So I tried adding it to /etc/sudoers (edited using techraf's suggestions): # This file MUST be edited ...
1
vote
1answer
50 views

Who could streamline this script better than what it is?, regarding mostly those tmp's

#!/bin/sh -e # # Usage: # ytpl song title # ytpl < titles # go() { echo "Playing $1" # Force TTY input for controls even if titles are read from input echo https://youtu.be/ > ...
0
votes
0answers
11 views

Variable from dialog box input doesn't behave as expected

I have a variable which the user sets by selecting from a dialog list. The variable is later used to cd. The variables are subdirectories in the format "sub.domain.tld." Import options array m here ...
0
votes
1answer
22 views

Tar compress directories and contents into individual, dated files based on folder name bash script

This is on a Debian system. I have had the compression of files and contents into individual folders working fine but not with the date added to the file names. Removing the date part, it works as it ...
0
votes
0answers
18 views

TFTP error code returned in bash

I have the below code to check on tftp error in my bash script. # fetch images from tftp server tftp_fetch() { echo "Fetching via tftp: $1:$tftp_path/$2" if ! tftp -g $IPADDR -r $...
0
votes
1answer
38 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: 3728.0M(3728.0M)->0.0B(...
0
votes
1answer
18 views

write a variable to a file on the end of a specific line

I want to add a variable to the end of a specific line in file file.txt. My code so far: #!/bin/bash read -p "What is the path of the repo? > " input echo :$input >> file.txt I want ...
0
votes
1answer
52 views

Linux: How does file modification time affect directory modification time and directory access time?

I would like to learn more about how file access time and file modification time related to directory access and modification times. I did read the "questions allowed here" but if there is a better ...