Bash scripting is making scripts in the Bash shell language.

learn more… | top users | synonyms

1
vote
1answer
289 views

How to mail output of shell script as a cron job

I've created a cron job that runs a shell script. I'd like the shell script to run and capture it's output and have it emailed upon completion. Here's what I have so far, but the mail message body ...
4
votes
1answer
53 views

Files with space in name

I have a variable called var that stores the list of files inside a directory. I loop through all the files and if I find a directory I output "Directory" to the screen. code below: var=$(ls dir) ...
0
votes
1answer
31 views

I want a for loop to go through files with two diffrent extensions

I want the following loop to go through m4a files AND webm files. At the moment I use two diffrent loops, the other one just replaces all the m4a from this loop. Also the files that ffmpeg outputs ...
1
vote
2answers
196 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
284 views

“line 3: syntax error near unexpected token” in a shell script

I am trying to run some executable with parameters several times. I wrote a script for it. But I am always getting an error and can't figure out on how to fix it. #!/bin/bash export ...
0
votes
1answer
38 views

bash script read line by line

Hello I am trying to create a script that reads my file take all the variable it needs then use it for another command. But it seems that the variables are not being memorized, because I tried a ...
0
votes
2answers
58 views

move command in linux to move multiple files of same extension but of different year

I have some 500 .txt files from the year 2013 to 2015 placed in a folder and I need to move all the files of the year 2013 and year 2014 to some oher folder.
0
votes
2answers
43 views

How do I ssh into a machine and cat a file on that box simulteanously?

Basically I want to remotely cat a file, this is what I have so far. It doesn't work. I'm fairly new to all this: echo /root/.ssh/id_rsa.pub | ssh root@HOSTNAME "cat >> ...
1
vote
4answers
231 views

cat all files except a select few

If there some particular syntax so that I can cat all files in a directory, except for the select ones. For eg., suppose I have ~1200 text files containing some lines, about 3 or 4 lines per file, ...
-1
votes
2answers
50 views

A bash script to call itself and return a value

I'm trying to count the number of files inside a directory while checking the sub-directories with the same script itself and sum up the results. #!/bin/bash var=0 var=$(ls -l $1 | grep "^-" | tr ...
1
vote
1answer
32 views

Basic Bash - If/Then with Boolean Operator

As you can see I set up a simple script to ping google(8.8.8.8) that should respond back with "Good Ping" if [ "ping -c 1 8.8.8.8 | grep 64 | cut -c 1-2" == '64' ]; then echo "Good Ping"; fi But ...
0
votes
1answer
115 views

How to redirect STDERR to both file and console and STDOUT to file only

What I want to achieve is redirect both normal message and error message to a file. But also print the error message to the console (only error message).
0
votes
0answers
37 views

How can I process traffic between 2 instances of NetCat?

I have an utility that make some data transformation between stdin and stdout in both directions (encode / decode), and I want to make a some kind of bi-directional proxy using two nc instances and ...
0
votes
2answers
140 views

How can non-root user monitor network traffic at command line?

I know that gnome-system-monitor can show me bandwidth even when opened by a non-root user. But tools like iftop, nethogs, etc. all seem to require root to work. How can I allow a regular user to do ...
0
votes
2answers
70 views

Why can't I redirect output from awk?

I've written this one liner to show MB read/written every 5 seconds. #!/bin/bash #iosum.sh iostat -dmz 5 |\ awk 'BEGIN{rx=wx=0}{if($0 == ""){printf"%.1f %.1f\n",rx,wx}else ...
0
votes
1answer
123 views

Cron strange behaviour

I've got a Bash script with all the permission to be excecuted, I attach it to to a cron job, this script basically only kill and restart a specific process, the strange behaviour is that if i run the ...
0
votes
1answer
39 views

How to kill a pid based on the result of an if statement

I'm trying to make a program restart if it has only one pid associated to it (it has to have two pid). if it has more than one it is ok, i've tried to write a bash script to do it but I'm struggling ...
0
votes
1answer
30 views

How to delete text after a marker

I’ve got a piece html code And I try to extract the first paragraph. html is like this : <p> Hi. Lorem Ipsum<br /> dolor si amet […] </p> <p>…</p> ...
0
votes
2answers
124 views

Is it possible to run programs nodejs in bash?

My question is simple : I have a program written in nodejs and want to run it in an infinite loop in the language bash, is this possible?
2
votes
2answers
90 views

How to add # Shebang in first line of a file which is an auto create script by another program

I am looking for a method to add a shebang #!/bin/csh -f to first line of my file , which is actually getting created by a another set of program, since this script is auto-created, it should run from ...
1
vote
1answer
35 views

using trap to close one program when another is closed

Ok...here's my goal....I use dwm, so normally I have no need for a compositing manager. That being said, there are times when I would like to have it running temporarily. There are times when I want ...
0
votes
3answers
153 views

How to escape binary data for inclusion into bash script

I want to create a bash script that reads a "payload" of binary data from an external file and spit out another bash script with this data escaped and encapsulated inside a string variable. Example: ...
0
votes
1answer
36 views

In Bash, can I have autocd open an editor if I enter a filename?

I’ve just set autocd in my .bash_profile: shopt -s autocd Now I can just type $ some-directory and automatically cd into it. Now, can I somehow tell Bash that if I enter not just a directory ...
0
votes
1answer
140 views

%T specifier in printf option of `stat` command

I want to know what is %T specifier in stat printf option and how it gets the file descriptor value ie., fd,1 is printed by using the below command. command is $> echo `stat -L ...
0
votes
0answers
22 views

How to have bash script run a bash command with

I am trying to have a bash shell in my desktop so that when I ssh to the server I can just run the command and have the script to open three terminal and have them cd in to a path and run another ...
2
votes
2answers
37 views

What is the function of & combined with > bash?

What is the purpose of & as in &> and &>> in bash?
-2
votes
1answer
95 views

How do I get the ip address via a bash script?

I have an application that requires you to input your ip address as a parameter, how to do I use a bash script to automatically get the ip address and have it put it in as a parameter for the program? ...
0
votes
0answers
94 views

How to receive sse (server sent events) and execute bash commands then

How do i receive server sent events (sse) from a webserver and execute a bash command with the received data in debian (raspbian)? Is that possible with curl as i can already receive sse. Thanks ...
0
votes
2answers
114 views

What language and how to test script that will run in android terminal app

I want to write a script that can run in a terminal app on an android device. I have basic questions about getting started. Background: I have a Windows batch file that (basically) pulls folders ...
-2
votes
2answers
24 views

options that can be used in if condition check

if [ -z "$1" -o -z "$2" ] - Here i know that -z option is used to check for zero length string but why we are using -o option along with -z. And also tell me any suitable link to study about those ...
4
votes
2answers
192 views

Manipulating datestamp string consistently with date format %Y%m%d

I need create log files that are essentially date stamps with prefix yp_ and suffix .log, and a manipulated day number: $ touch yp_$(echo "$(date +%Y%m%d)-10" | /usr/bin/bc -l).log $ ls ...
0
votes
1answer
203 views

Deleting oldest files to free space as needed on Linux

I have a cron job that writes logs to /tmp. I want to automatically delete the oldest files when the free space in the disk becomes less than 1GB. I'm trying to do df -ah /tmp, then take the 2nd ...
-2
votes
2answers
89 views

Automating Homebrew [closed]

I'm currently using the Homebrew package manager, and I have to say that it is really really great! My question is: there is a way to automate brew update and brew upgrade in order to execute this ...
0
votes
1answer
57 views

Access xinput from acpi bash script on debian

I'm trying to program a non-working special key on my keyboard using the acpi events, and already got acpi to recognize a keypress and pass it on to a shell script. However, for some reason I cannot ...
0
votes
3answers
220 views

Store output of a command in a variable without losing $? value

I'm developing a bash script. I need to take the output of a command and store it in a variable, and I need to know if that command was successful. My intention was doing this(pseudo-code): var = ...
-1
votes
1answer
308 views

Can't send email from a bash script

#!/bin/bash SMTPTO=akshaysingh@gmail.com SMTPFROM=akshaysingh1@gmail.com SMTPSERVER=smtp.googlemail.com:587 SMTPUSER=akshaysingh SMTPPASS=password MESSAGE="123" SUBJECT="THIS IS END." sendemail -f ...
0
votes
0answers
169 views

How to transcode a video to XviD format with GStreamer?

I'm trying to script a GStreamer pipeline to transcode videos to my Meizu M6 miniplayer. I found some scripts to do the transcoding with mencoder, but would like to do that with GStreamer. The device ...
3
votes
1answer
27 views

splitting separate bashrcs for different purposes

I was wondering if I can split my .bashrc into separate parts, and linux will pick up both files and use them correctly. I have general purpose scripts like 'cleanproject', and scripts that are only ...
0
votes
2answers
106 views

How to insert lines into specific files in which a string is not present?

I'm looking for some help with a small script. I would like to search all files corresponding to /usr/local/directadmin/data/users/*/httpd.conf for the string centralized.log If the string is ...
1
vote
3answers
44 views

Determine Partition OS

Is anyone aware of a way to determine the OS installed on a separate unmounted partition without mounting it in Linux? I'm trying to determine which has Windows installed with a script while live ...
0
votes
1answer
93 views

Alias that runs a sub command

I want to run 2 commands under an alias, but since it includes cd and I don't want to change folder from the main caller, I thought it may help calling a subcommand: alias lhu="$(cd /my/path ...
1
vote
2answers
502 views

escaping awk with remote ssh command and bash that is already escaped

Hello. ssh ufk@10.0.0.2 "bash -lc 'pm2 list | grep app | awk { print $3} '" I need to run the command I pasted here. the problem is that i'm already escaping twice... the bash with " and the pm2 ...
0
votes
1answer
181 views

How can I rename all image files within a directory (and recursively within its subdirectories)?

I have a directory containing a large number of image files, some of which are in subdirectories. I need to rename all image files matching *.png, *.jpg, *.jpeg, *.bmp, *.gif using a simple pattern ...
1
vote
2answers
191 views

Alternative to 'ls -A' in Bash

Is there an alternative to ls -A command in native bash functions? Wildcard * isn't the same. I tried hard to find one, but echo * doesn't show hidden files.
0
votes
1answer
129 views

Tar progress per file with pv for multiple files/folders at a time?

I've been using this one line command that I found on another post here and it works great for one folder at a time. This is the command: tar -cf - /opt/folder1 | pv -s $(du -sb /opt/folder1 | awk ...
1
vote
2answers
314 views

Concatenate csv-files with the same name from subdirectories

I found some scripts concatenating text files from different subdirectories, but all of them produced output files like "output.txt", but didn't keep the original file name. Structure Folder_A ...
1
vote
2answers
205 views

how to gzip and scp at the same time

I have a file in which i wanted to zip up and at the same time transfer over to another host using scp. I tried to do the following command but failed. I do not mind zipping up and scp over later, ...
1
vote
3answers
153 views

BASH: finding partition from diskutil output

I'm trying to search the output of a command listing local drives to find a partition called EFI on the boot HDD. I've written a really dirty oneliner as I can't seem to work out how to effectively ...
0
votes
1answer
78 views

Pass a path with parenthesis and space in system call inside awk script

Inside my simple awk script, I call system command #!/bin/bash Test='/home/software/Other/new (Applet)' ls "${Test}" var=$(ls "${Test}") echo $var awk -vTest="$var" 'BEGIN { ...
1
vote
2answers
222 views

How to recursively create a hash file (sha512sum) inside each folder of a tree?

For a given tree, say /var/ftpd, how do I create a hash file in each folder of that tree with the contents of that folder within a given tree? sha1sum and sha512sum does not have recursion options. ...