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

learn more… | top users | synonyms (2)

0
votes
1answer
42 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
75 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
46 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
78 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
46 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. "aaa"...
3
votes
2answers
51 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
66 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.
0
votes
2answers
41 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
45 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
39 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
92 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
41 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" ...
0
votes
1answer
36 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
103 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 * * * /home/server/...
3
votes
2answers
29 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
85 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
39 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 '28s/^/'$b'\...
3
votes
2answers
57 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
2answers
71 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
56 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
60 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
72 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
177 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
93 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
39 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? http:/...
3
votes
1answer
37 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
38 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
34 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 :28C:...
1
vote
2answers
85 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
33 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
89 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 /media/...
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 ...
0
votes
3answers
49 views

Issue with the shell script after storing the directory in a variable

FTP is connecting to the server but i am getting an error - Enter if the env is dev or test or prod: test Please enter the id no : xxxxxxx Connected to xxxx 220 (vsFTPd 2.2.2) 331 Please specify the ...
1
vote
1answer
32 views

how to inject keystrokes in a program like Safari from a bash script?

I am trying to automate some keypresses every few minutes. The exact timing is still undetermined. But basically I want to capture a live chat dialogue. I'm sure I could do this more elegantly. I don'...
1
vote
1answer
43 views

Printing the file with number of hardlinks

I can print the number of hardlinks to files in directory by using find . type f -printf "%f %n\n" but this will also print the hardlink not only original files: Example: file1 is an original ...
1
vote
1answer
42 views

Rc.local not running commands properly

I am running arch Linux and have used this rc-local service: [Unit] Description=/etc/rc.local compatibility [Service] Type=oneshot ExecStart=/etc/rc.local RemainAfterExit=yes [Install] WantedBy=...
71
votes
1answer
7k views

Why does the following script delete itself?

If you create an executable file with the following contents, and run it, it will delete itself. How does this work? #!/bin/rm
0
votes
2answers
39 views

.sh query - running a ssh task

This is on a macintosh but it's still unix command. I am running some computers on a network that have file sharing turned off because of security so the only way to connect is via ssh. I need to ...
1
vote
0answers
25 views

Access to bash arrays in gnuplot [duplicate]

In a bash script I have several arrays which I need to access in a gnuplot code: #!/bin/bash ... # fill array a[*] and b[*] ... gnuplot <<EOF do for [j=0:10] { # access ${a[j]} and ${b[j]} } ...
-3
votes
1answer
63 views

Need help in a shell script

I need help with the below shell script. I have three environments: test, dev and prod. When the user enters test it should ftp to test host and ftp the file. Same in case of dev and prod. I have just ...
0
votes
1answer
38 views

tar directories containing spaces [duplicate]

I want to archive my photos into tar archives. The directory containing photos has one dir per year and multiple dirs inside each year dir: Photos 2005 2006 Some dir with spaces ...
0
votes
0answers
37 views

Fixing Signal 13 Error on find

I have a situation where I'm trying to install softwares into my system. I'm using a fakeroot approach to install them in a separate directory where I'm listing all the files, directories and links ...
3
votes
3answers
109 views

Reverse sequence of a file with POSIX tools?

Is there any clean, clear-cut POSIX equivalent to tac? Readability as well as succinctness should both be considered.
1
vote
0answers
14 views

Linux Mint Corners Musical Sequence Associative Array

I am writing a script which uses hot corners to play specific musical notes when hovering in corners, and depending on the musical sequence to execute a specific command. The script is called with ...
3
votes
2answers
91 views

Accessing Google-translate via wget

I don't want to call the whole Firefox/Chrome/Opera... to find out the meaning of a word with the Google translate, so I decided to write a shell script which uses wget to get the content of translate....
0
votes
2answers
46 views

How to use file test to check if a file already exists in a directory

I'm trying to write a script that asks the user if they are sure they want to move a file to a certain directory. The script needs to check if the file already exists in the target directory and if it ...
4
votes
2answers
91 views

Millisecond time in a shell script

How can someone print the entire time ie, for example 12:07:59:393(HH:MM:SS:milliseconds) in milliseconds. I found a lot of posts saying how to print Milliseconds along witht HHMMSS but I want to ...