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

learn more… | top users | synonyms (2)

1
vote
1answer
162 views

running script at specific times without using cron [duplicate]

I'm trying to run a shell script in (#!/bin/sh in HP-UX) on exact times(hh:mm:ss) hh:05:00 .. hh:10:00 .. hh:15:00 .. hh:20:00 .. hh:25:00 and so on. I understand this could be done using cron but I'm ...
1
vote
1answer
136 views

Using cURL command-line tool on Mac, how does one fetch stock data which comes back *without* commas? [duplicate]

The below script is not working. cd desktop/quoteUpdate while true do curl-o quotes.txt -s "http://download.finance.yahoo.com/d/quotes.csv?s=goog,aapl&f=sl1" sed -i '.bak' 's/,/ /g' quotes.txt ...
5
votes
2answers
267 views

Two-words argument in shell script

I have a problem with a shell script. It is supposed to read arguments: index, date, time1 (the beginning of the interval), time2 (the end of the interval). It should count how many times the ...
-1
votes
2answers
112 views

Shell script issue when added to cron

I have written a shell script in order to monitor Nagios service status continuously (See this question), which is as follows: #!/bin/bash RCPT="abc@xyz.com" service nagios status | grep [0-9] if ...
1
vote
1answer
90 views

script needs to add another loop

script which runs netstat -tulpun | grep -i port_from_the_list & takes the output for running the next command I need to run 2 command on all the server mentioned in the list. server: Jan port: ...
0
votes
0answers
27 views

Pcmanfm keeps deleting and recreating my thumbnails

I wrote a little shell script to handle cbz/cbr thumbnails in Pcmanfm instead of using Evince and every GNOME thing coming with it. The thumbnails are created and can be used normally BUT they seem to ...
0
votes
2answers
75 views

Fetching data from server by FTP command

"Fetching data from server by FTP command" is not a problem .But if I like to fetch the today's file from the server, whose name is like (BACKUP20141210) and if it presents in a folder with previous ...
3
votes
5answers
817 views

Awk - output the second line of a number of .dat files to one file

I have searched through previously asked questions and can't find an answer to what I am trying to do. note, I am new to linux. I have multiple files something like: (in reality i have 80) file1.dat ...
0
votes
5answers
124 views

Getting the shellscript to display a chosen file extension

I'm new to this with shellscript and Linux and now I'm stuck. I shall write a simple program that allows me to search for andy file extension I want and then display how many of them there are. I've ...
1
vote
1answer
49 views

Computing differences of column entries

I have a textfile with: 1 100 2 80 3 70 4 64 Now I need another file that contains the first column equal to above and the second column should be the difference of to consecutive values of the ...
1
vote
2answers
64 views

remove lines from an output file from diff

I have a script that uses diff -c then puts the output on a text file. What I want is to remove the line that does not have the "!" and display the lines with the exclamation mark. Is this possible? ...
1
vote
3answers
260 views

How do I make an output for grep fail?

I am using if-else statement to search for keywords and displaying the results in the terminal, here's an example of my code. read finding if ["$finding" != "" ]; then grep $finding ...
-1
votes
2answers
51 views

Script which takes details from file & runs command

It would be helpful to understand how can I connect the second column in the script. currently using the below for loop for i in cat server do echo ===$i==== ssh -q $i 'netstat -tulpun ...
1
vote
1answer
58 views

How do I display the whole line of text?

Example of my information: Fruit,Quantity:Cost,Sold Red Apple,10,1,5 Green Apple,10,2,20 Orange,20,1,10 Here's my code: if [ "$fruit != $blank" ] && [ "$quantity" == "$blank" ]; then ...
1
vote
2answers
433 views

Can I put more than 1 condition in if?

Is it possible to put more than 1 condition in an if statement? if [ "$name" != "$blank" && "$age" == "$blank" ]; then Is it possible? If not how am I supposed to do that?
-2
votes
1answer
46 views

'Is a directory' while trying to pass to destination directory

I've been trying to get my script to work from a cron job so that I can automate a backup of my /home directory, but unfortunately when I run with run-parts to test if the script will work I keep ...
0
votes
1answer
82 views

Build system for shell scripts

At my workplace, there is a Bash script which is used to list Oracle databases running on a farm. I have made some modifications to it, using some inlined Python code (ex: python -c "import sys..."). ...
2
votes
5answers
172 views

How to combine & and &&?

This is the type of question which is very hard to search for! I have a shell script that goes like this: #!/bin/bash ./script.fcgi --socket /tmp/fcgi-socket & sleep 2 chmod a+w ...
0
votes
1answer
138 views

How do I put a checksum in a script?

I was (am) having trouble installing Eagle on my Linux (debian 8 jessie) computer. I was reading the installer script, when i noticed there is a checksum for the install script in the install script? ...
0
votes
2answers
72 views

Whats wrong with this case statement?

UPDATED: I am trying to do some color changes with my keyboard using apexctl depending on what time it is. But my case statement is giving me trouble. I want to compare the time when the script runs, ...
1
vote
1answer
99 views

How can I examine RUNLEVEL from a bash script on Rasbpian?

I'm writing a bash script that needs to examine the current runlevel, and do different things depending on it. For most Linux distros, it seems there should be a RUNLEVEL environment variable, and if ...
1
vote
2answers
357 views

Get files from SFTP server and manipulate in memory

Is there a BASH way that is able to access a SFTP server, "access" a file and without downloading it read it in a buffer, manipulate the content and then store it locally. I know this can be done ...
1
vote
2answers
300 views

Compressing multiple files in different folders without folder structure

Currently I create a copy of my log files like this: # tar -cvzf /var/www/vhosts/example.com/httpdocs/myfiles.tar.gz /var/www/vhosts/example.com/logs/access_log ...
3
votes
3answers
651 views

How to pass the content of a file as multiple arguments in bash

I have a file that contains data that gets updated over time (mydata). The file looks like this: 1 2 3 With this file, I want to do this (basically handle each number as a separate parameter): ...
2
votes
4answers
191 views

Flattening folder structure

I have this folder structure: ├── foo1 │   ├── bar1.txt │   └── bar2.txt ├── foo2 │   ├── bar3.txt │   └── bar4 with a space.txt └── foo3 └── qux1 ├── bar5.txt └── bar6.txt that ...
2
votes
2answers
102 views

How to print out every other line to the monitor

Have this tiny script down below and want to print out to the screen every other result. What are the ways of doing it? #!/bin/bash for ((n=5, j=1; j<=9;j++)) do echo "rez: $n*$j"=$((n*j)) done ...
1
vote
2answers
115 views

How to use process substitution within a case statement without getting syntax errors?

I have a script loaded as a service in /etc/init.d/myfile When I try to start the service I get the error /etc/init.d/myservice: 21: /etc/init.d/myservice: Syntax error: "(" unexpected The issue ...
2
votes
2answers
232 views

Why does my cronjob not execute my shell-script?

I have a crontab that creates a dump of my database every night: 20 3 * * * /path/to/dailydump.sh dailydump.sh contains: #!/bin/sh DATENAME=`date +%Y%m%d` ...
2
votes
2answers
269 views

Collect files from several different directories and put them in one place

I have a large amount of ebooks that are very disorganized. Some of them are alone in their own directories, some of them are corrupted, some of the directories are empty. How do I gather my ebooks ...
0
votes
1answer
266 views

Run a script that displays an X window from an udev rule

I found several questions on http://unix.stackexchange.com & on http://stackoverflow.com related to launch script by udev rules. But I can't find exact solution or certain answer for executing ...
0
votes
1answer
38 views

Prepending text read from a file on the top of another file [duplicate]

I want to add "void mainfunction()" on the top of a file. I am reading the actual name of the file from another file and the name of the main function from another file. I was using sed -i '1i void ...
2
votes
2answers
1k views

parse one field from an JSON array into bash array

I have a JSON output that contains a list of objects stored in a variable. (I may not be phrasing that right) [ { "item1": "value1", "item2": "value2", "sub items": [ { ...
3
votes
2answers
191 views

Select lines starting with specific numbers

I have to show the PID, PPID and STATUS of the procceses on the system, but only the ones which PID starts with numbers in the range 5-8. So i tried something like this... ps xao pid,ppid,s | grep ' ...
1
vote
2answers
68 views

Modifying part of a string in bash script

I have a file named variables.f90 , having many lines defining different variables, as follows :: integer::n_monomer=6800 real*8::rx=5.0d0 #... randomly integer and real numbers defined ...
1
vote
1answer
48 views

How does executing a file change the std input?

Imagine I have a script, which contains the goto command. The goto command will search in the std input for a line like this : jumpHere. But the std input is by default the terminal. It only makes ...
7
votes
2answers
874 views

Was there a '\0' at the end of every script?

I'm wondering how did you dertermine the end of a script/file? I'm especially interested for old Unix versions (like V6). Is there a '\0' after the last written character?
3
votes
2answers
109 views

terminal warn on close when opened within a script

First, the question: How can I warn the user that a script is running when the user clicks the close button and the terminal itself (and the process running in it) was started from the command line. ...
2
votes
1answer
362 views

awk in ssh in su in a command substitution

I am creating a script that will ssh to a host and print all the user accounts and when they will expire. On a host I can run awk -F':' '{ print $1}' /etc/passwd and it will give me a list of all ...
0
votes
1answer
130 views

create a user via script

I want to create a new user in a specific group when I issue the below command. sudo ./create_user.sh "test" "firstname lastname" The create_user.sh script looks as below. #!bin/bash #sudo ...
0
votes
1answer
100 views

Can't concat file paths, permission denied

I can't realize why if I just try to concat some file paths (without opening the files), I get "permission denied": #!/bin/bash if [ "$#" -eq 1 ]; then path1= "./src/$1" path2= ...
1
vote
2answers
69 views

How to make a filter more efficient

I've created a script to compare a list of users from a MSSQL database against a list of disabled AD users. The tool we use for AD authentication returns data in the following format (with plenty ...
1
vote
3answers
204 views

iterate over file and send lines as positional parameters to another file

I would like to iterate through a file containing dates (named dates.txt) in the following format: 2009 08 03 08 09 2009 08 03 09 10 2009 08 03 10 11 2009 08 03 11 12 2009 08 03 12 13 2009 08 03 13 ...
0
votes
0answers
149 views

open Mysql connection for long time to execute queries in block

I am writing one script which execute bunch of queries in block. here block means version number, each version have different different queries. I write two shell script. 1 version.sh version.sh ...
1
vote
3answers
144 views

Can I make [ $(($1 % $check)) -ne 0 ]; be more performant and not be killed?

If have the following code which works for up to 13 (line 2) in a few seconds but when I try and do upper teens and 20 it gets killed after a couple of minutes. divisible_by () { for ((check=2; ...
-2
votes
1answer
3k views

Why do I get “-eq: unary operator expected false”? [duplicate]

I get $ ./5_divisible_by_1_to_10.sh ./5_divisible_by_1_to_10.sh: line 16: [: -eq: unary operator expected false true for: divisible_by () { under_test=$1 from=2 to=4 divisible=0 for ...
2
votes
1answer
143 views

Avoid backslash expansion with echo in dash

First create a file with this exact content: a\nb I named this file foo, if I run the following, it prints the exact content of the file: bash -c 'bar=$(cat foo);echo "$bar"' But if you run it ...
4
votes
1answer
99 views

Simple problem, Long read: How to overwrite file residing on ESP at Linux boot

First, foundation. Here is my setup: I have a 64-bit dual-boot system running Windows 7 and Linux Mint 17 Cinnamon. I use rEFInd to graphically choose which system to boot. A little bit about ...
38
votes
2answers
4k views

Why is using && 75 times faster than if…fi and how to make code clearer

I have the following working code: largest_prime=1 for number_under_test in {1..100} do is_prime=true factors='' for ((divider = 2; divider < number_under_test-1; divider++)); do ...
1
vote
1answer
42 views

How to use passed-in parameters for shell script?

I know little about shell script but I want to try to implement some complicated scripts. Say I have a doitall.sh with the content like: zip -j version_a_en.zip en_filea1.txt en_fileb2.json And a ...
2
votes
1answer
2k views

How to use variables in sed command

I'm trying to run sed -i "/$variable/c \$variable1' file.txt But it's not displaying any change in the file: file.txt. But the same command, with out the variables works fine: sed -i "/variable/c ...