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

learn more… | top users | synonyms (2)

2
votes
0answers
40 views

How to get the executed command of a process which has completed successfully using the PID?

I have small script, abc.ksh that takes 3 parameter e.g abc.ksh ${a} ${b} ${c} I will read from a config file with 'n' no of entires and I will execute abc.ksh 'n' times in parallel using a for loop. ...
2
votes
2answers
89 views

Using tar with find

Lets say we want to find a certain files , use tar on them and delete them. I tried using touch "mycompress.bz2.tar" find . \( -name "*.c" -o -name "*.sh*" \) -exec tar ujf "mycompress.bz2.tar" {} ...
0
votes
2answers
37 views

Awk: Print last N columns, where N is passed through a variable

My input variable $dirPath contains directory path. The action is to be able to retrieve the last N values in the directory path, where N is passed through a variable $depth. For a fixed N value (say ...
0
votes
1answer
56 views

Prepare update command using sed

I have a output file that contains 3 different column data- ['AARF'],SAMPLE12,2016-01-05 12:00:00-0500 ,529OFFST,2015-04-16 08:04:21-0400 "['EPROSP_IWS', ...
1
vote
1answer
39 views

Find All images file size and width in directory

I'm trying to find all .png .jpg and .gif files in my directory. I'm getting the file sizes properly but unable to get image width (I'm using imagemagick) in log file. Script code #!/bin/bash for d ...
1
vote
2answers
32 views

Repeating current loop iteration if some condition is met (bash)

I'm writing a bash script which takes files and directories as arguments. It will loop through its arguments and rename the current argument if some condition is met. When this happens I want also to ...
2
votes
3answers
35 views

echo all *.tex filenames in a specific directory

I have a directory structure like this: ├── lebenslauf │   ├── lebenslauf.out │   └── lebenslauf.tex ├── thirdPage │   ├── auto │   │   ├── test.el │   │   └── thirdPage.el │   ├── missfont.log │   ...
0
votes
3answers
64 views

Defining bash function dynamically using eval

I'm trying to define a bash function dynamically using following code: delegate_function() { echo "output from delegate"; } eval "parent_function() { echo $(delegate_function); }" The intent is to ...
3
votes
2answers
26 views

Improving execution speed of Screen Brightness Script

xrandr --output LVDS-1 --brightness $(bc -l <<<"$(sed 's/Brightness: //' <<<$(xrandr --prop --verbose | grep Brightness)) $(if [ "$1" = "+" ];then echo +;else echo -;fi) 0.1") I ...
0
votes
2answers
58 views

How to run a shell script on 10 hosts simultaneously? [duplicate]

Currently I am monitoring 10 hosts. I want to write a script which will calculate the disk space in every 24 hours and then if the file system of a host is critical for any host then it will move the ...
0
votes
1answer
24 views

jq capture - how to properly key with captured string

I routinely use lshw -json to abstract system data on Linux hosts. In the current scenario, I've extracted network data from lshw via lshw -c network -json and have need of extracting, further, data ...
1
vote
2answers
38 views

Scope of Local Variables in Shell Functions

After reading 24.2. Local Variables, I thought that declaring a variable var with the keyword local meant that var's value was only accessible within the block of code delimited by the curly braces of ...
1
vote
0answers
21 views

How to write decorator commands [duplicate]

I don't know the exact word, that's why I'll use "decorator", like in POO, but I'm talking about the kind of functions you can use before other functions to add any operations to it, like the command ...
1
vote
1answer
31 views

How to run a for loop block which is within a shell script after connecting to another server using sftp?

The script.sh takes a list.txt (which contains list of files present on both server A and server B) file as command line parameter and reads the list .It then connects to server B using sftp and ...
-5
votes
1answer
58 views

Exit a program by pressing the key q

I have wrote a shell script in which I would like to include the functionality to exit the program by pressing the q key. Can I do that? Here is what I currently have: #!/bin/ksh echo "Press Q to ...
0
votes
2answers
34 views

Daemon to: receive messages -> run background command -> manage number of tasks running simulatenously?

Looking for a unix program that runs in the background (daemon), that: can receive arbitrary (JSON) messages. On receiving a message, run a specified command. Has option for limiting number of ...
1
vote
3answers
70 views

Using time on bash functions (not commands)

How can one measure individual calls to bash functions from inside the bash file. I have a program that I call using the command eclipse -b col_solve.pl -e "myPred" This call outputs some ...
2
votes
3answers
41 views

Bash read with delimiter past newlines

I have a csv for which I have to extract a specific field. The csv is pipe-delimited (|), with double quotes (") to protect text fields and (this is the catch) newlines in some of the text. eg. ...
3
votes
2answers
48 views

Compare multiple files with ref file and print if it matches

I am new dummy user of Unix, so excuse me for maybe easy question. I have multiple files which look like this: b alternate_ids rsid chromosome position alleleA alleleB index ...
-5
votes
1answer
56 views

Shell script to delete logs when the disk space reaches 90%

I need help to develop a shell script to delete the logs automatically once the disk space reaches 90%. I can add this shell script to crontab jobs.
24
votes
2answers
1k views

How to merge two text files into one file without using cat or sed? [duplicate]

I have two files File1: a b c File2: 1 2 3 now I need to combine them to one csv file a;1 b;2 c;3 As the files are really huge, I would rather not use cat and sed to process the second file. ...
0
votes
2answers
40 views

One shell script to perform commands locally and remotely

So, here's the problem. I have a file on a remote machine available only to root, and a private-key-only no-root SSH access(I do have sudo though). I need to copy that file to the local machine, and ...
0
votes
1answer
44 views

Matching and storing and the returning information to standard input

So I'm really stuck here. I got some files with millions of lines of data in them formatted like so: username|process name|process time (in minutes) There are close to 3.4 million lines of this ...
0
votes
1answer
38 views

bash program to execute something when keyword seen on stdin

Suppose I have an executable which connects to an external machine and outputs a bunch of stuff to stdout over many minutes. At the end of that output there'll be a keyword such as "STOP", or the EOF ...
3
votes
2answers
72 views

posting data using cURL in a script

I'm trying to write a simple alternative script for uploading files to the transfer.sh service. One of the examples on the website mentions a way of uploading multiple files in a single "session": $ ...
1
vote
3answers
39 views

case statement not behaving as expected (fuzzytime() function)

FuzzyTime() { local tmp=$( date +%H ) case $((10#$tmp)) in [00-05] ) wtstr="why don't you go to bed" ;; [06-09] ) wtstr="I see your very eager to start the day" ...
-4
votes
0answers
41 views

Join column with columns of next two line in shell script

I want to join value of the first line with the value of next two line. If some value includes number (G, G1, G2) in input data, It should be considered for all combinations. For example, input ...
0
votes
1answer
28 views

syntax error: unterminated quoted string when using regexp_replace in bash script

I've added some code to the end of a bash script I am using. The code shown here is intended to copy a csv into my postgres table, and then remove brackets, quotes and double quotes from the title ...
1
vote
3answers
92 views

add text on line before match

Trying to add text on the line before that it find the match (updateKey.sh) in this case, but won't get it to work. Here is my crontab file that the script adds the line to 0 06,18 * * * ...
3
votes
2answers
28 views

Limiting System Libraries that an Program Can Use

I have a program that runs under Linux. The program crashes if a particular library exists on the system but runs normally if the library is not present. (It only seems to look for the library at ...
0
votes
5answers
83 views

Delete N lines, keep the next N and so on

I want to delete the first 12 lines from a file, keep the next 12 lines and repeat this to the end of the file using a Linux command or shell-script.
0
votes
1answer
36 views

Bash add text on line script [closed]

Trying to get my script to work but it won't work. Here is my script #!/bin/bash a="* * * * * /home/server/scripts/check.sh" b="0 06,18 * * * /home/server/scripts/checks2.sh" sudo sed -i ...
3
votes
2answers
50 views

How to export a variable from a perl script into a shell script?

I have a shell script in which I am running perl script by below code. perl perlscript.pl In the perl script I have defined a variable called $circle. Now I want to use this variable value in my ...
1
vote
1answer
50 views

move files with special characters to new directory

I'm trying to write a loop for a script that checks a specific directory for any special characters and moves those files to a specific directory (except spaces and hyphens - those are simply replaced ...
3
votes
2answers
49 views

Send command output to screen and syslog

I'm trying to send the output of a command to our syslog and this is what I have so far. #!/bin/bash log() { logger -s -t $(basename $0) "$@" } /bin/echo "test" 2>&1 | (log) and this ...
3
votes
0answers
46 views

Memoizing/caching command line output

I have a bash script I use to run a few python and C++ programs in a sequence. Each program takes in some input parameters which I define in the bash script. So as an example I run the program like ...
0
votes
4answers
66 views

How to remove duplicate rows from a file?

File, TABLE1 ------- 1234 TABLE1 ------- 9555 TABLE1 ------- 87676 TABLE1 ------- 2344 I want the output like TABLE1 ------- 1234 9555 87676 2344
1
vote
2answers
59 views

How to modify (not add to) a number variable?

Suppose that a=$((1)) How can I change the value of a from 1 to 01? I just want to insert the 0 before the current value of a and rewrite it. a=$((01)) would not be a solution in this case because ...
9
votes
2answers
163 views

Shell Syntax: How to correctly use \ to break lines? [duplicate]

I used to believe that the appropriate way of breaking the lines in a list is command1 && \ command2 It turned out that it isn't so , one doesn't need \ $ [ $(id -u) -eq 1000 ] ...
0
votes
1answer
69 views

How to pass a parameter with space in nohup? [duplicate]

I have script to run a jar, like shown below. user="Tim Tom"; jarfile=./app.jar SC_CD="java -jar -Xms512m -Xmx2048m -DUSER='$user' $jarfile" nohup $SC_CD And im geeting error message as Error: ...
-4
votes
1answer
35 views

Unpack a shell archive (.shar file)

I have a shell script. How can i remove anything before # this line Everything before the # should be deleted. The script is too long to delete it manually. How can I do that automatically? ...
3
votes
1answer
34 views

If there are more than x number of pipes in a csv line, then delete the 2nd instance

I have a csv file which is supposed to contain 4 columns of data which include a product number, a title, a url and a price. Each column is separated by a | delimiter (this has to be maintained, there ...
0
votes
1answer
37 views

How to maintain only four lines in my file in shell scripting?

Input file: 01.05.2016 87893938 02.05.2016 35435345 03.05.2016 35435345 04.05.2016 12345678 I want to keep only four lines in my file. that means if date 05.05.2016 6905698 is inserted then ...
0
votes
2answers
33 views

Add newline character to file

Hi Guys i need to change the below single line string using a shell script {1:F01NESWSZM0AXXX1111111111} {2:I940BBRUBEBBXXXXN} {3:{108:400MSOG161200FRO}} {4: :20:400MSOG161200FRO :25:1xxxxxxxx65 ...
1
vote
2answers
79 views

sh AND and OR in one command

Trying to check for 3 conditions in one line of code, but I'm stuck. Essentially, I need to code for the following: IF string1 is not equal to string2 AND string3 is not equal to ...
14
votes
5answers
1k views

Compress a large number of large files fast

I have about 200 GB of log data generated daily, distributed among about 150 different log files. I have a script that moves the files to a temporary location and does a tar-bz2 on the temporary ...
1
vote
2answers
51 views

How to rename certain directories if the parent has a particular name?

I have to do some global renaming in an Eclipse plugin project, although the fact that the code is Java and it's an Eclipse plugin is irrelevant. Basically, the steps I need to perform are the ...
0
votes
1answer
25 views

custom shutdown script in rc6.d does not seem to be working.

I'm working with a software application that's a bit touchy so I wan't to shut the software down automatically on reboot or shutdown. I have created a script an placed it in /etc/init.d/ with a ...
2
votes
1answer
80 views

Cannot mv to a subdirectory of itself

I am running this simple script and I am trying to create a cron job so that the file gets copied to my thumbdrive (with the new name) sudo cp /home/pi/NewLog.log /media/usb sleep 20 cd ...
3
votes
1answer
36 views

Why does this script not accept two arguments?

Code #!/bin/sh # http://tex.stackexchange.com/a/20886/13173 # http://unix.stackexchange.com/a/280830/16920 # $Id: pdf2eps,v 0.01 2005/10/28 00:55:46 Herbert Voss Exp $ # Convert PDF to encapsulated ...