Bash scripting is making scripts in the Bash shell language.

learn more… | top users | synonyms

0
votes
1answer
15 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 ...
11
votes
3answers
7k 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
5 views

bash script error when running executing openvpn service

I am trying to develop a bash script that calls a service from within: #!/bin/bash interface=dev0 mycommand="sudo openvpn --config '/etc/openvpn/optionFile.ovpn'" $mycommand When I run the script ...
2
votes
3answers
531 views

list multiple file types in bash for loop

I wrote a script that converts images in a folder. The script uses a for loop: i="1" for file in *.jpg; do outputFile=$(echo "image"$(echo $i)) convert "$file" -resize 50x50 $outputFile ...
0
votes
0answers
11 views

Stop bash script with any key

I'm writing a script which I want to stop with any key I choose. After pressing the key, my intention is to complete all my commands at that moment and start su. I've tried adding a & to my ...
0
votes
2answers
79 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 ...
5
votes
3answers
370 views

Suppress execution trace for echo command?

I'm running shell scripts from Jenkins, which kicks off shell scripts with the shebang options #!/bin/sh -ex. According to Bash Shebang for dummies?, -x, "causes the shell to print an execution ...
0
votes
1answer
18 views

Extract the first 2 letters in each line of a file using a single command Terminal

I want to extract the first 2 letters of each line from a file and save it in a variable and print it in a single command. Can anyone help me with the command? Considering my file has 20 - 30 lines ...
-1
votes
1answer
22 views

Script to Update time

I am using a old laptop which lacks a battery so the wake-up time is during 1980. Thus, I use the NTP service to update the time to the current time.Is there a script to achive this. My os is ...
0
votes
2answers
111 views

Bash Script to generate <name> and pass this as command line argument to programm

I have an python script which gets 1 command line argument python arg Now I want a bash-script which: calls python arg & with the argument arg=000 make this x-times so therefore: python ...
1
vote
1answer
28 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 ...
0
votes
2answers
444 views

Execute a command and put the results into a variable… all in a bash script

I'm working on a bash script that backs up a configuration file before copying over a new file. Here's what my snippet looks like: mv ~/myStuff.conf ~/myStuff.conf.bak cp ~/new/myStuff.conf ...
0
votes
2answers
7k views

Why can't I delete a file with a bash script

This may be a silly question, but I can't seem to run rm from a bash script and remove a file. #!/bin/bash rm -rf myjunk.out exit 0; doesn't remove myjunk.out
3
votes
2answers
33 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
29 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 ...
0
votes
1answer
43 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) # ...
1
vote
2answers
416 views

How do i run su username -c “command ” in a sequence

am trying to write a script that runs commands in a sequence as a user but su keeps doing every command at the same time instead of running them one after another the script looks like su username ...
0
votes
0answers
11 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
26 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 ...
-2
votes
2answers
52 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" = ...
0
votes
2answers
952 views

How do I concatenate strings from a list in a bash script?

As an example: List="A B C D" for I in $List do OUT=$OUT" -$I" done When I run this the result is: " -A -B -C -D" but want it to be: "-A -B -C -D" How do I concatenate without the ...
3
votes
2answers
39 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
45 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
50 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) ...
1
vote
0answers
82 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
1k views

My bash script does not find an existing file

I realized a bash script that works on an existing text file located into the same working directory of the script. The script take name of the file to compute through a function parameter. The issue ...
0
votes
1answer
25 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
1answer
6k views

Removing files older then 1 month, but leave files created at the 1st day of the month

I'm trying to remove some archive files from a folder on a CentOS fileserver with a cronjob. The requirements: Remove files of the last month The .tgz-file of the first day of the month should be ...
0
votes
1answer
51 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
35 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 ...
4
votes
1answer
6k views

Handle filename with spaces inside Bash-script

In my Bash-script I have to handle filenames with spaces. These are the important lines inside my script: mp3file="/media/d/Music/zz_Hardcore/Sampler/Punk-O-Rama\ Vol.5\ \[MP3PRO\]/01\ -\ Nofx\ -\ ...
0
votes
2answers
36 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 >> ...
0
votes
2answers
38 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
1answer
107 views

Sharing variables between applescript and bash script in same script

Is it possible, in a bash script, to have a variable, but also allow applescript (with osascript) to use that variable?
0
votes
1answer
78 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 ...
1
vote
4answers
163 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
46 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 ...
0
votes
1answer
34 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 ...
1
vote
1answer
24 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
28 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
42 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
28 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
69 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
48 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
120 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
27 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> ...
13
votes
4answers
11k 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
52 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?
0
votes
3answers
87 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: ...
2
votes
2answers
57 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 ...