Bash scripting is making scripts in the Bash shell language.

learn more… | top users | synonyms

1
vote
1answer
34 views

for loop (f in *.txt) throws error if no *.txt file exists

I have a small bash script which looks something like this: #!/bin/sh for f in ./*.txt do f=$(basename $f) echo "Processing $f" scp somewhere mv $f done/`basename $f` done This is working ...
3
votes
2answers
39 views

Bash scripting: 365-024=345?

I am trying to build some beginner scripts with bash. I want to find how many days left from today until the end of the year, using date program. So I am using a variable, current_date=$(date +%j) to ...
1
vote
3answers
35 views

Show which command failed

command1 && command2 && echo "OK" || echo "FAIL" This will print OK if both commands succeeded or FAIL if either of commands failed. How can I modify this to print: OK if both ...
1
vote
1answer
51 views

Behavior of same commands (under Bash) - running one by one in console vs as single script

Running on OS X 10.11.1, I execute the following series of commands (one by one), in the console: FILE="a b c.tiff" # file in the current folder VAR=$(mdls -name kMDItemContentCreationDate $FILE) # ...
0
votes
0answers
36 views

Add remmina rdp connection entry on many computers

i want to add remmina rdp connection entry on many computers (~200). I know that the remmina keeps every connection entry in single file in ~/.remmina, so i wanted to write script that will copy this ...
0
votes
0answers
75 views

Can the wmic command reliably be used in script batch files?

I believe that the following command: wmic product where "name like '%%winzip%%'" call Uninstall shuts down PC's when deployed with SCCM. Has anybody came across any issues with the command similar ...
-1
votes
2answers
101 views

Bash: if [ tar = error ] [closed]

I want a shell script to write a message depending on whether tar succeeds or fails, but this script doesn't work correctly: TAR=$(tar -cf Archiv.tar myfolder/ myotherfolder/) if [ ! "$TAR" = "/dev/...
3
votes
2answers
70 views

make file size at least 1MB

I'm trying to learn about operating systems by making one myself and testing it in virtual-box, but VBoxManage convertfromraw doesn't allow my source file to be very tiny (512B). Are there any bash ...
1
vote
1answer
587 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
37 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
262 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
400 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 VCF_FILE='...
0
votes
1answer
42 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
80 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
45 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 >> /root/.ssh/...
1
vote
4answers
249 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
52 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
36 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
181 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
48 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
191 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
93 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 if($0~/^Device:/){rx=wx=...
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
43 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
31 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> <p>…<...
0
votes
2answers
171 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
107 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
37 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
208 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
37 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
183 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 /dev/mapper/...
0
votes
0answers
23 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
133 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
111 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
130 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
210 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 yp_20150912....
0
votes
1answer
315 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 line,...
-2
votes
2answers
110 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
60 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
298 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
362 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
177 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
29 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
118 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
46 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
114 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
655 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 ...