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

learn more… | top users | synonyms (2)

0
votes
1answer
27 views

Move selected information form one TXT file to ANOTHER

I have two txt files: config.txt and template.txt template.txt has to take relevant information from config.txt Let's say config.txt contains: colour1: red colour2: blue And template.txt contains:...
0
votes
1answer
27 views

Linux redhat crontab + run script with arguments

I add the following line to the red-hat crontab in order to run the script /var/scripts/info_from_all_sites.bash every Friday at 00:00 night script should get as argument the file - /var/RT/names....
2
votes
2answers
30 views

finding a folder names based on list contained in .txt file

I have a .txt file containing 150 different ID number on each line like so: 12345 15876 19643 12586 Located in the same directory as the .txt file, I have 300 folders and I want to copy only the ...
2
votes
2answers
49 views

Bash function comments before or inside the function [closed]

Does the Bash language have a standard that dictates whether comments about the function should precede the function or be placed inside of it. I have seen scripts written both ways. # Comment ...
7
votes
7answers
346 views

grep the exact block of lines (content of file1) from file2

I have two files, file1 and file2. The sample content of file1 is: A B C D E F G H and the content of file2 is like: A B few other lines E F few more other lines A B C D E F G H few more other ...
3
votes
1answer
103 views

Handling whois connection refused message in shell script

blacklist_ips=' 5.56.148.140 94.73.159.66 69.134.15.72 107.150.42.226 195.159.233.44 89.19.7.58 ' for ipx in $blacklist_ips do country=`whois $ipx | grep -i country | tail ...
0
votes
1answer
33 views

Automatically put content in for read in bash

Hi I have a little bash script and before i used to type the content in a bit like answering a question, but what i would like to do is just run the bash script and instead of answering the question ...
2
votes
1answer
39 views

Search for files inside multiple subdirectories and zip directories [duplicate]

I need to extract more than 2k files from 1000 folders..the problem is, each folder has a zipped folder inside and inside this folder, there is another folder called "fileholder" which contains some ...
-1
votes
1answer
34 views

cancel script execution and continue [closed]

I have a script which runs another script. myscript.sh #!/bin/bash .... cd /folder/ sh run.sh sh another_script ... the procedure: So , I start running myscript.sh , the script runs it's ...
3
votes
0answers
114 views

How can I run 'ls' with options from a C program? [migrated]

I want to execute the command ls -a using execv() on a Linux machine as follows: char *const ptr={"/bin/sh","-c","ls","-a" ,NULL}; execv("/bin/sh",ptr); However, this command does not list hidden ...
14
votes
3answers
432 views

Replace environment variables in a file with their actual values?

Is there an easy way to substitute/evaluate environment variables in a file? Like let's say I have a file config.xml that contains: <property> <name>instanceId</name> <...
0
votes
0answers
47 views

Regular expression in expect command

I need to match a string and a newline with a regular expression or something like split when using the expect command on Linux. Here is the example of the command output: Notification value: 34 39 ...
1
vote
4answers
95 views

/bin/ls: Argument list too long

I am a biology person and running a program named autodock. I have some files from ZINC library in .mol2 format. As per requirement I need to split this files with the csplit command and I received ...
1
vote
2answers
59 views

chown doesn't work through script

I have a script: #! /bin/bash sudo chown -R $USER:$USER /opt/Folder The chown doesn't seem to execute. If I just write the above line from terminal ,it runs fine though! I have read this but ...
3
votes
1answer
40 views

Rename directories from “fname [mname] lname” to “lname, fname [mname]”

I have a bunch of directories with author's names as "first [mi] last" (middle initial/name could be multiples), and I'd like to change them to "last, first mi". So I'd like a way to parse the name ...
0
votes
2answers
70 views

im getting “syntax error near unexpected token” error in my shell script

when I run the particular command in a console it works fine but when I run using start script..it throws error. #!/bin/bash # chkconfig: 2345 20 80 # description: Description comes here.... # ...
3
votes
1answer
46 views

Cannot trigger tmux script on boot

I have a tmux triggering script as mentioned below, running on Raspbian Wheezy 7.10: Step 1 #!/bin/bash # this script is called "sess" tmux new-session -d -s sess1 'sudo /home/pi/bin/myscript.py' ...
4
votes
1answer
44 views

Open a new terminal, monitor it and execute a script

I have a script that I want to monitor its results and write them to a log file. I run the following: gnome-terminal -x bash -c "script logfile.log; ssh user@IP" But this command execute first the ...
1
vote
1answer
38 views

Pipe demon output to a function

I'm receiving a MQTT message with mosquitto_sub and I want to redirect the output (two strings) to a function. CLIENT: mosquitto_pub -d -t hello/world/ -m "Alessio,base64" On the server I have a ...
2
votes
2answers
47 views

help to construct grep output

I have a command I am using #cat test |grep "Ongoing Calls" |awk -F' ' '{print $3}' 40 2 As you can see it returns 2 values 40 & 2 I want to now add these together and put into a file as 42 ...
4
votes
3answers
79 views

Shell script to separate and move landscape and portrait images

I have a directory of jpg images. Is there a shell script (bash or zsh would be acceptable) that would move all landscape images into a directory, and all portrait images into another directory?
0
votes
3answers
59 views

Want to print a table format with multiple line in shell scipt

I want to print the line in a table format using sed or awk or any other in a shell script. example Line1 Line2 Line3 Line4 Line5 Line6 Line7 Line8 Desired Output Line1 Line2 Line3 Line4 Line5 ...
1
vote
3answers
71 views

Read lines from a file into a variable

I'm trying to automate a large process to save time and effort and I'm probably making it way harder than it needs to be. What I'm doing so far is: #!/bin/bash LISTFILE="/tmp/filename" for FILE in $...
5
votes
4answers
91 views

Is there an easy way to do the equivalent of `sed …` replacing the same line with multiple values?

I have a file where I want to replace some variables with data from a shell script. -A INPUT -i lo -s @LOCAL_IP@ -j ACCEPT Here I want to replace @LOCAL_IP@ with an IP address, I use the following: ...
0
votes
1answer
70 views

Writing output of command to variable [on hold]

I would like to put the output of a command into a variable. As far as I know, you have to use either of these: variable=$(command) variable=`command` The following should work from my point of ...
1
vote
0answers
31 views

evaluating dual blocking commands in a bash condition statement

I am attempting to write a loop that refreshes a terminal either 1. when the file(s) have been modified, or 2. When user input is detected second interval. I know how to do one at a time, like so: ...
0
votes
1answer
43 views

Build a sitemap from local PHP forum pages

I've been reading stackexchange for years now, and always managed to find an answer to the problems I had to deal with. This time however, I'm going to ask a question as I could not find a solution to ...
0
votes
3answers
51 views

How to delete lines in file from specific position to the end of the file

I have a file with many lines. I want to delete from the line 1458 to the end of the file. I think that I can do it with sed, but I do not know how to.
1
vote
1answer
45 views

Find case duplicate files and rm uppercase

I have a number of image files that have duplicates across case (ie file.jpg File.jpg). I need a script like the following except I want to completely remove all uppercase. I know that fslint can do ...
2
votes
0answers
52 views

Bash completion extra space when adding file directory

I have a script for extending bash-completion for certain commands. If I type command1 and do a tab, it should auto-complete with a file directory (and the files). It works fine expect for one ...
0
votes
1answer
37 views

how to properly pass _set_ of parameters with spaces into shell function

My problem is not simple passing parameters with spaces (I know how to achieve that), consider more complicated case: function build() { make CC="$1" CFLAGS="$2" $* # $* is not correct here! } ...
2
votes
4answers
268 views

New line in variable

I want to create a config file with a .sh file. I can't figure out how i insert new lines. The code i already have: domainconf='<VirtualHost *:80>\n ServerName '$fulldomain'\n DocumentRoot '$...
0
votes
2answers
75 views

Wildcard not working in quotes

The script is supposed to loop over subdirectories and match all the filenames (FLA.*Image.*file.jpg and FLA.*Image.jpg) in subdirectories and process it. It also create output folder inside the ...
1
vote
0answers
26 views

Should I quote variable when passing to command? [duplicate]

I always do this when passing variable to command mkdir -p "$dir_to_make" are those quotes needed? I tried to google but didn't find much. I always write them, just interested if they are necessary....
0
votes
2answers
65 views

Suppress warning messages from MySQL in shell script but allow errors

My log files are getting dumped with following message while running shell scripts using some underlying MySQL commands. Here is the message: "Warning: Using a password on the command line ...
0
votes
1answer
37 views

7zip and Move Files with Spaces in Bash Script [duplicate]

I'm trying to 7zip and move some files that look like this: ./[1998] - This year's book.pdf ##note the brackets, spaces, and apostrophes My script looks like this: for file in `ls ./unprocessed/*....
0
votes
1answer
33 views

How to save the dynamic input from command line to a file in the same format as input using Shell script [duplicate]

I want to save dynamic multiline input from command line to a file in the same format as input. For Eg: Code to get the dynamic input: echo "Enter the multi-line message" message=$(sed '/one.*/q') ...
5
votes
5answers
191 views

How do I speed up a script based on a grep search?

There is a very large text file with two comma-separated values: 78414387,10033 78769989,12668 78771319,13677 78771340,13759 80367563,16336 81634533,10025 82878571,10196 110059366,10218 110059411,...
-3
votes
1answer
64 views

Rename all files

I have 800 file with naming as: Centrum.text.201601-01 Centrum.text.201601-02 till 30 for a month 01 and so on for all the 12 months . I want is to rename all the files in a single go as: ...
-2
votes
1answer
29 views

Issue while substring a line while reading a line from a file

DMGR_PATH.out file Contains /opt/IBM/WebSphere/70/AppServer/profiles/Dmgr01/config CELLNAME /IBM/websphere/was7.0/profiles/Dmgr01/config CELLNAME Now I have tried to read this file and substring ...
1
vote
0answers
31 views

How to run Firefox from script?

I can run Firefox without a desktop environment by running the following commands in succession in a virtual console: sudo pkill lightdm X &>/dev/null & DISPLAY=:0 compiz &>/dev/...
4
votes
2answers
41 views

Bash - Integer expression expected

I am making the check for update script for my theme I have 2 text files. First one is called "current.txt" and contains the current version. There is 4.1.1 string in that text file. Second one is ...
1
vote
0answers
18 views

GTK gtkdialog window to make a link

I'm trying to make a pop window that lets you select a dir . in the back ground this will make a link to that dir. im using bash scripting and gtkdialog /home/rich/movies --> /home/rich/content/...
1
vote
0answers
11 views

Fluxbox, how to launch specific instance of application in a workspace (from cli)

This almost does what I want Fluxbox, how to launch some applications in a specific workspace at startup but not quite. I want to be able to save the position and workspace of a specific instance of ...
1
vote
2answers
47 views

Distinguish between command that typed by human and run by script

For example $ pwd /home/my_name It is possible or not to identify that this command is typed by human or run by script.
1
vote
1answer
42 views

Is there a way to use apostrophes in sed commands? [duplicate]

Is there a way to use apostrophes ' with the sed command? I mean this: - sed '-2 a\\ What's up?' text I am talking about the apostrophe in "What's up". If I do it like this it gives me an ...
2
votes
3answers
41 views

Find a specific file in the nearest ancestor of the current working directory

I'd like to find a way to find a given file by looking upward in the directory structure, rather than recursively searching through child directories. There's a node module that appears to do ...
2
votes
1answer
29 views

Remove silence from audio files while leaving gaps

Currently we're using this command within a shell script to remove silence from audio files: ffmpeg -i $INFILE -af silenceremove=0:0:0:-1:1:${NOISE_TOLERANCE}dB -ac 1 $SILENCED_FILE -y This works ...
0
votes
1answer
43 views

script set command output to variable [duplicate]

I'm writing a simple script that prompts the user for information and saves it as a variable to be passed as arguments in another command. One of the variables stores a path which may include a space. ...
0
votes
1answer
38 views

How to determine if script is called by interactive shell or another script?

It's fairly straightforward to determine from within a script that the code being run is not running in an interactive shell, but you already know that as you write the script, so I'm not sure how it'...