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

learn more… | top users | synonyms (2)

1
vote
2answers
47 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
53 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
32 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
30 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
43 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
55 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
51 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
60 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
58 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
36 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
745 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
72 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
70 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
35 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\" ...
-1
votes
0answers
24 views

Script for checking OU/OC trend for last few FGC cycles

I have a script in place which sends alerts regarding cluster memory utilization and some other info. My issue is that for some clusters the memory utilization(in % age) trend has to be checked at ...
4
votes
3answers
150 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
51 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
62 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
36 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
422 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
43 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
91 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
71 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
39 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
64 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
29 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?
1
vote
1answer
103 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
106 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
82 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
35 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
56 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
85 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
86 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
39 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
72 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
54 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
26 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
24 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 ...
-3
votes
0answers
49 views

Bash Script for Renaming files

I need a shell script, which can rename all the files in the folder, Like Go into the designated folder, Search for all the files like Core.3467 core.1234 core.acde and change it to like ...
1
vote
3answers
72 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
23 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
78 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
49 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
66 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
39 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 ...
0
votes
0answers
5 views

Fine tuning of an informative replacement for rm [migrated]

I want to replace rm by a more informative variant: I would like to see which files will be deleted, along with their size, and I would like this information to use the same coloring as ls. I built ...
2
votes
4answers
60 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 ...