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

learn more… | top users | synonyms (2)

1
vote
4answers
55 views

How to move all files (excluding sub-directories) from one directory to another?

How do you move all the files (excluding sub-directories) from one directory to another. I'd prefer if the solution used just basic shell scripting.
2
votes
1answer
62 views

SSH command not exiting properly [closed]

I wrote a script that SSH to remote servers in loop and run a command, it gets hung after running on last server.Here is my loop script - cat server | while read serName do ...
1
vote
1answer
59 views

How to make awk work in a while loop

input.txt: /usr/dir1/file1 /usr/dir1/file2 /usr/dir2/file4 /usr/dir3/file5 Script: cat input.txt |while read FILENAME do nawk '{print $1}' ${FILENAME} >> output.txt done Expected output: all ...
0
votes
1answer
77 views

load bash comands from file one per line and execute them for each file in a directory

I'm trying to write a bash queue which will be able to load command set from a file and then execute each over set of files. prepared file should serve as a template for execution in manual bash ...
3
votes
1answer
41 views

Condition on finding a file

I'm trying to write a script which looks for a file and if it is found, saves the full path to a variable. Current version: if [[ -n FOUND_PATH=$(find "$PATH" -name "file.exe") ]]; then echo ...
0
votes
0answers
15 views

Accessing HTML pages through command line for scripting [duplicate]

There is a web page that I usually do the same thing over and over on. Click a button, enter some text and that's it. Is there any program that allows me to interface with a webpage with a couple of ...
3
votes
2answers
31 views

Setting variable with default value behaves differently when preceding a command?

Setting a variable with a fallback default value works...as long as we're using the variable in a subsequent command: $ unset APP_ENV $ echo $APP_ENV $ APP_ENV="${APP_ENV:-production}"; echo ...
1
vote
2answers
53 views

Remove x lines before and y lines after nth line (which matches a pattern) in a file

I'm trying to remove a four line block from a text file if the second line matches the Regex N+. The text file is composed of many repeating 4 line formats, ie: @HEADER1 ACTGCNNNT + 583@#!NMY ...
0
votes
4answers
54 views

Excluding specifics lines from being redirected [closed]

Let's say I am executing a script like this : /a/b/c/script.sh >> abc.log This will mean that all the contents/execution of script will be re-directed to abc.log. If I want a particular line ...
0
votes
1answer
33 views

Redirect stdin for multiple shell functions [closed]

I'm surprised nobody has asked this before - maybe I'm just that dumb? How to I force this script to do what I intended? #!/bin/bash function One() { IFS='' read -r -n1 CHAR echo "One: '$CHAR'" ...
0
votes
1answer
31 views

Calculate swap values dynamically

Can someone please let me know if the below should work as i am not sure and getting error? Just to let you know that i am using in one of my nagios script ## GET SWAP Warning and Critical values ...
2
votes
2answers
46 views

How to make this loop Ctrl+C-interruptible?

# wait for host to become online while true; do ping host -c 1 -w 3 > /dev/null && break; sleep 1 done When I press Ctrl+C, the ping receives it and exits with exit code 1 (the ...
0
votes
3answers
62 views

Best way to obfuscate aix script

What is the best way to obfuscate shell script in aix? The problem is that is a shared user and I would like to the other don't know the code.
1
vote
3answers
66 views

Random sampling and outputting the largest value

I have a fairly large data set ~500 million rows. The data set looks like below. Col 1 is float number, col 2 is mac id(device id) 1616.93,ac:22:0b:a6:22:c3 2872.32,c0:bd:d1:36:bb:49 ...
1
vote
2answers
54 views

Matching “keyword value” pairs from semi-structured input

On occasion I get output from a command that includes "key value" pairs, with possibly more than one pair per line. As a repeatable example, consider the command ip addr show dev eth0: ip addr show ...
1
vote
1answer
106 views

How can i use multiple if statement inside another if statement of a awk program?

I have a CSV File and i want to have multiple checks to retrieve the data from the CSV file. I have the following conditions which needs to be taken care of and i am trying to use awk in a shell ...
0
votes
2answers
68 views

Telnet check in bash script

I want to run following commands in bash script form in Solaris 10: $ telnet localhost 25 debug quit How I handle this?
1
vote
1answer
44 views

bash ignorecase match pattern in file and color that line, print all to screen

I have almost zero idea about coding or bash scripting, so please bare with me and excuse my horrible formatting. What I want is to cat a log file and highlight certain lines with color based on a ...
10
votes
3answers
757 views

What's a smart way to count the number of days since X?

I started working at my current position since November 17th 2014. I would like to know how many days have run up to now. Any ideas on how to use Linux to come up with a simple and nice solution ?
0
votes
1answer
18 views

Setting arguments from a text file does not work

Here is my code. #!/bin/bash set -- $(cat /home/jeevan/tempzen1.txt) zenity "$@" file tempzen1.txt contains : --list --title FILE-SELECTOR --column serialno. --column file --width 1000 ...
1
vote
4answers
75 views

Problem with entire function in a script

I want to detect online network/shell services in my Solaris. I write following script for this purpose: compare_ser() { if [ "$1" != "" ]; then echo "True" >> Solaris.txt fi } export -f ...
1
vote
1answer
130 views

How to select rows from a CSV file based on different column values?

I have a CSV file with values like the following: col1,col2,col3,col4,col5,col6,col7 1,0,0,0,0,BTS,Active 4,5,3,1,1,LocalMode,Offlne 1,2,5,6,3,PermFault,Offline 1,2,6,6,2,BSC,Active ...
1
vote
2answers
38 views

Something wrong with spaces in zenity trying in a script [duplicate]

While this is directly executed in terminal it works fine zenity --info --text "pure info" --title "get info" But this script doen't work what's wrong? !/bin/bash ZEN="--info --text \"pure info\" ...
4
votes
3answers
170 views

Bash script: do something one time inside a loop then stop, but continue looping

I have a Bash script that checks my laptop battery and sends me an Android notification (via shuttle, a Bash script I wrote that serves as a cli interface for the Pushbullet API). It works nicely, but ...
3
votes
2answers
81 views

Create thumbnail from video at random time frame

I'm using this bash script to generate thumbnails from videos: #!/bin/bash source_dir="." output_dir="/output" input_file_types=(avi wmv flv mkv mpg mp4) output_file_type="jpg" r1=$(( ( RANDOM % 10 ) ...
1
vote
2answers
81 views

how to store output of a command into array with each value in a double quote

I want to store each output in double quoted array values. values can have space also. FOUNDFILES=($(locate --database ~/.locate.db -i -b "$INPUT")) if input to the locate command is very very ...
1
vote
1answer
47 views

How to parse a CSV file based with groups made of specific number of rows?

I have a CSV file which has the following format: Date,Towns,Count1,Count2 6/26/2015,HYDERABAD,234552,0 ,KARIM NAGAR,7520,0 ,RAJAMUNDRY,7248,256 ,KURNOOL,5848,32,0 ...
11
votes
3answers
480 views

Date validation in shell

I want to validate the below date format in shell script 2015-Jul-13 I'm using date -d "2015-Jul-13" +"%Y-%b-%d" but its giving error as date: invalid date '2015-Jul-13'
-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
95 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
81 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
57 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
77 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
36 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
162 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
114 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
86 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
82 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
93 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
90 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
61 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
28 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
148 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
39 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
92 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 ...