Questions about shell scripts, executable files that are interpreted by a shell (bash, zsh, etc.).

learn more… | top users | synonyms (2)

-1
votes
1answer
44 views

Whats wrong with the 2nd script?

I am new to linux and scripting. I have some concerns regarding the script below which creates folder per line from file. Folder.list is located in /scripts/ . 1st script works smoothly but the 2nd ...
1
vote
6answers
96 views

How can I pass an environment variable to a script?

Okay, I can display an environmental variable from the commandline: echo $COLUMNS And get a response. But I can't execute that from within a shell script, I get nothing. So, there must be a way to ...
2
votes
4answers
87 views

What's the name of the environment(?) variable with current terminal width?

I know this is something simple, but I can't recall where it's located/named. Where's the variable for the current width of the terminal stored? I see this answer talks about changing things: How ...
1
vote
2answers
66 views

cronjob timing - for every 3 months

I chanced upon this example: 0 9 1-7 * 1 * First Monday of each month, at 9a.m. I am not sure the 1-7 portion which is supposingly to be the dates of each month. Why is it a ...
1
vote
2answers
82 views

“Argument list too long” in for loop

My shell script look like this: #!/bin/bash for file in *.fasta do signalp $file > $file.txt done In the working folder I have 18.000 .fasta files. I want to run each through the signalp ...
-1
votes
2answers
40 views

Can I design an android app using shell script? [closed]

Is there a way to design android app using shell script? If so how?
0
votes
1answer
185 views

How to add custom script to plank (dock) in Elementary OS Freya

I am using Elementary OS Freya. I want to add custom bash script to plank (dock). How can I do it ?
0
votes
5answers
116 views

Shell script to run a program with arguments

I am setting up game servers via SSH and was wondering if I could execute one file that could be run with arguments (like Windows Batch files) without having to type it out so long. What I want is a ...
0
votes
4answers
87 views

given a file, find where within a subdirectory it was copied to

Given a file that I know has been copied into a given directory, I want to find the exact path where the file copy now resides. It is guaranteed the file has not been edited and will look exactly like ...
1
vote
2answers
38 views

Make a Scheduled job for Renaming the files in a folder and send an updated alert email

I am writing a shell script, which can rename all the files in the folder, We need to search for a particular pattern of files every 30 seconds. Files in the below format need to be selected, ...
-2
votes
2answers
87 views

Checking if a file exists and print the result to an excel file [closed]

I want to create a batch file which reads the list of files and the corresponding directories from an excel file and checks them if they exist in the unix location and create a flag if they don't ...
1
vote
5answers
94 views

How to get all numbers out of a string and add them?

I have to parse a .xml file generated to summarize the results of a running a testSuite on some software. In a line I have, for example: <Summary failed="10" notExecuted="0" timeout="0" ...
3
votes
2answers
95 views

How do you know you are on the last line when looping through a file?

I have a file called listing.txt It contains data like: 1 2 3 4 5 I then use the following to loop through the file and do stuff with each line: IFS=$'\n' while IFS= read -r inc; do if [ ...
1
vote
1answer
43 views

Trying to store the output of file command into a variable , but the output says “no such file exists”?

This is my shell script: $EXTENSION=$(file $RADIOOUT) $RADIOOUT contains the file name along with its path. output is: ./zenityentry: line 40: =/home/jeevan/Downloads/p.txt:: No such file or ...
1
vote
3answers
76 views

how to break a line after matching a certain character using shell command?

File1: John Daniel Hommes Cameron;Emily Terry Mussy Barbara Mimi Papu;David Swiss Jen Hans Peter Iril;Kelvin Lilly Gucci Kate Nik;Forum Bill June;Jill and Jack Output file: John Daniel Hommes ...
0
votes
2answers
63 views

How to count the number of words of each sentences in a file using shell command?

I have text files like this: Mr.P.K.Baneerjee has visited the site today at 4.30pm The permit tag has been set in the ds busbar Opearation has been performed in presence of control engineer Opeation ...
1
vote
1answer
30 views

Bash script only runs in debug mode [closed]

I have the following bash script: #!/bin/bash -e SUDO=sudo $SUDO apt-get -y update || true $SUDO apt-get -y install lxc bridge-utils || true # remove the default bridge, if it exists ...
2
votes
1answer
30 views

How to tar-bzip old files in yearly groups

I wish to know a command I can use to grab and archive all files for a year at a time. I am working on a directory that has 72000 files, with files dated from 2007 to current. And I wish to make that ...
1
vote
3answers
176 views

Save a list of files over SFTP to a text file

I have provided my own answer below. We have a number of bash scripts that work fine using SFTP, what I would like to do is to simply re-direct an ls or dir of a folder to a file on our SFTP Server.. ...
1
vote
1answer
43 views

Send javascript to Chromium or Firefox from linux terminal

I am using either a chromium or firefox web browser in kiosk mode to log in to a website from boot up, and I want to use a javascript to send in a command to login to a website automatically. I know ...
-1
votes
2answers
95 views

check if string represents valid path in BASH [duplicate]

I currently have a directory in a string, as such: DESTDIR="/var/files/mydir/filedir/" Note that this directory does exist. I made sure of that. I need to check if this directory already exists, ...
0
votes
0answers
15 views

mkdir in shell script failing with \r [duplicate]

I have the following basic shell script: #!/bin/bash mkdir /var/lib/mysql/backups/test rm -r /var/lib/mysql/backups/* ROOTDIR="/var/lib/mysql/backups" TODAYDIR=`date +%Y%m%d` mkdir ...
0
votes
2answers
60 views

how to grep the file names based on the date formate

We have hourly and daily files in the same folder: data-2015-06-06-00.tsv data-2015-06-06-01.tsv data-2015-06-06-02.tsv data-2015-06-06-03.tsv data-2015-06-06.tsv data-2015-06-07-03.tsv ...
0
votes
3answers
69 views

How to achieve “continuos randomness”?

With RANDOM%xone gets a set of discrete results. How can I achieve following scenario?: Inside a for loop, I'd like to let a bash script execute command A in 33.33% of all loops and else execute ...
0
votes
1answer
53 views

Bash if statement not working properly [closed]

I have a bash statement to test a command line argument. If the argument passed to the script is "clean", then the script removes all .o files. Otherwise, it builds a program. However, not matter what ...
2
votes
4answers
67 views

How to parse table for pattern if pattern includes spaces

A continuation of this question: parse first column of command output, get corresponding second column value Say I have a command that outputs a string formatted as a table, as shown below. What if ...
4
votes
3answers
69 views

Go from a String to an Array of “words” in Bash

I need to go from a string to an array where each entry is each word on that string. For example, starting with: VotePedro="Vote for Pedro" I need the array: Vote For Pedro Which I should then ...
3
votes
3answers
56 views

Wait for key in shell script that may get piped to /bin/bash

Consider the following shell script echo foo; read; echo bar Running bash my_script outputs 'foo', waits for the return key and outputs 'bar'. While this works fine running it that way, it doesn't ...
1
vote
1answer
61 views

Exiting a script called from another script via SSH

Suppose that bash script X is being called within another bash script Y. If I directly execute script X on a local machine, after X's completion, the program exits to the terminal. However, when I ...
0
votes
1answer
29 views

Running a command on different shell

While reading the answers of question Can bash write to its own input stream?, I found following command runs on zsh but not on bash : print -z echo mnciitbhu 1 . Is -z is an extension to print ...
2
votes
4answers
170 views

How to influence a bash while loop with a timed global variable?

I have a while loop in a bash script which should do something different at the beginning and at every 5 second interval. Any previous loop is allowed to complete. The 5s interval is indicated by the ...
0
votes
1answer
105 views

parse first column of command output, get corresponding second column value

I am fairly new to BASH scripting for Linux. I am executing a command that outputs a table, as such: firstValue: a secondValue: b.y7 thirdValue: c-x-g 10:42 GMT Say I need the secondValue. I ...
1
vote
1answer
67 views

What does colon (':') in bash variable resolution syntax mean? [duplicate]

Could you help me decode this assignment: jvm_xmx=${jvm_xmx:-1024} Can't understand, what it does.
2
votes
1answer
80 views

Updating environment variable in a shell script

I am trying to update the value of an environment variable in a third party shell script. My OS is Oracle Linux Server release 6.4 (Red Hat Enterprise Linux Server release 6.4 (Santiago). I already ...
1
vote
2answers
253 views

How can I check how many files have been created in one week?

How can I check how many files have been created in one week? Situation: The system will create four files at every week, if the system is running normally. For example: A_08-07-2015.csv ...
-1
votes
1answer
59 views

No such file or directory error when attempting to run shell script upon startup of console [closed]

I'm trying to run a shell script upon startup in cygwin. I have added these commands to my .bashrc file: $ echo 'export MAIN="D:/dev/Main" >> .bashrc > echo '.MAIN/Env/tpsScripts/devenv.sh ...
1
vote
0answers
21 views

Build Script Help, Not Loading Modules

So I am writing a script to build and install Netcdf, but when I source it, it seems like some of the lines just are not running or are being skipped and I am unsure why. When I run the code line by ...
2
votes
2answers
98 views

Assign variable identifier in loop and echo its value

I hope this question is not a duplicate because I've been trying various ways to solve this problem but couldn't find any solution. I have a for loop in which I'd like to store a command output into ...
1
vote
3answers
82 views

Using a function defined in a parent script

I wrote the following script in the test.sh: #!/bin/sh compare() { if [ $1 != root ]; then echo "Fail" >> CAT1.txt fi } awk -F: '$4 == 0' /etc/passwd | cut -d: f1 | xargs -n1 -i bash -c ...
1
vote
2answers
148 views

Write bash_history to a file with a timestamp

I need help with the script below. The requirement is to capture command line history in a file with specific date and time of commands, when they were executed. The below script captures history ...
2
votes
1answer
47 views

How to read and do a min/max/avg from a NMEA stream

I have a weather station attached to my device spitting NMEA 0183 on /tty/USB0 I have alreeady sorted out how to parse the data and echo what I want in a script. What I need to do now is write the ...
0
votes
1answer
82 views

/bin/sh script error “arithmetic expression: expecting primary: ” + “ ”

ERROR: ./client-disconnect.sh: 22: ./client-disconnect.sh: arithmetic expression: expecting primary: " + " I just need to know how to fix it. It's for user accounting with OpenVPN. Script ...
0
votes
2answers
85 views

Extract numbers from a text file and place them in another file

I have a text file whose contents looks like this: ...
1
vote
4answers
82 views

optimize command with or and pipe to parse the output of ifconfig

I have this command line, but it's doubling the grep and awk ifconfig eth1 2> /dev/null | grep "inet " | awk '{gsub("addr:","",$2); print $2 }' || ifconfig eth0 2> /dev/null | grep "inet " | ...
1
vote
0answers
31 views

How can I use arptables to limit the number of outgoing ARP requests a second?

End goal: Make a script that will limit the number of outgoing ARP requests in a second using arptables. This is to have the ability to not trip the ARP-limiting feature on Cisco devices. I want to ...
1
vote
1answer
28 views

What's the Fedora equivalent of /var/lib/dpkg/info/[…].prerm?

Example file: /var/lib/dpkg/info/util-linux.prerm What's the Fedora equivalent of this file? (Not limited to util-linux - generic question for any package.) Use case: A prerm script is failing. ...
0
votes
1answer
272 views

How to execute R script attaching it to a shell script in Linux?

I am trying to submit a job to be executed on cluster. And this is done by writing an sbatch submission script. The job involves opening R 3.1.3 and running the referenced R script on the server. ...
2
votes
2answers
88 views

Sort files with a specific extension by modified time and store them into an array

I have found many answers to sort the files of directory and even to save them in an array. Sorting Example ls -t Directory listing in array array=(*) My particular problem needs to sort files ...
1
vote
2answers
39 views

Script to Compare the “file size” with “last name of file” and if unmatched delete the file

In my environment, we'll be receiving files from clients into our Sftp. Sftp process the files, and move it to another tool, by appending the file size at the end of the file name. For example, ...
8
votes
1answer
360 views

Are [ “$VAR” = “” ] and [ -z “$VAR” ] always equivalent?

My code looks something like this: VAR="" while [ -z "$VAR" ]; do VAR=$( command | grep "important_string" ) done So I want to poll the output of command, until the important_string appears and ...