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

learn more… | top users | synonyms (2)

0
votes
2answers
65 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
44 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
34 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
75 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
58 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
65 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
90 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
44 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
50 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
63 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
32 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
62 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
41 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'...
1
vote
1answer
29 views

Asking your script to accept arguments which contains whitespace [duplicate]

I'm really stuck on my scripting because of this problem. I need my script to accept arguments and give me the result but since i have spaces it only displays the first word. eg. cat open.sh echo My ...
1
vote
1answer
39 views

Catch number of syntax errors in shell script [duplicate]

EDIT: This question was marked as duplicate. While this might be true on a larger scale, the answer provided by Kusalananda gave me a better understanding of my options. If a syntax error inside a ...
1
vote
2answers
62 views

How to print all subsets of a set? [duplicate]

How can I print all subsets of a set using bash script. like : {} , {1} ,‌{2} ,{1,2} for A={1,2} this is what I have already write but I always thinks there must be a better way also my script just ...
1
vote
1answer
48 views

Initilization script runs twice on SSH

Running Ubuntu 12.04. I have a script that sets up the environment, its run by /etc/bash.bashrc. (It may be set to run by other shell profiles inits, I didn't actually set it up myself) When I Ctr+...
6
votes
5answers
367 views

bash + using printf in order to print in special format

I just wrote the following bash script to check the ping access on list of Linux machines for M in $list do ping -q -c 1 "$M" >/dev/null if [[ $? -eq 0 ]] then echo "($C) $...
1
vote
1answer
35 views

read the file and assign the values to another file

I want to read the file and assign the values to variables whic is in another file using shell script. For example I have file as "myconf" cli="/opt/Solartis_Monitoring/JON_CLI/bin/rhq-cli.sh" user="...
0
votes
1answer
22 views

How to check not starts with condition in if statement?

I want to check the condition like below. Line should not starts with # symbol if[ ! ["$Line" == "#*"] ]; then But this is not working.. somebody help on this plzzz.
2
votes
1answer
41 views

redirect output of command to /dev/null

I run the following line from my bash script in order to run the script /usr/run.pl on remote machines xargs -P "$numprocs" -I '{}' -n 1 -- perl -e 'alarm shift; exec @ARGV' -- "$timeout" ssh -...
0
votes
1answer
38 views

command not found using sudo in script

I am trying to execute sudo command inside a bash script. #!/bin/bash sudo node app.js and it throws me : sudo: node: command not found If I try to execute only node app.js (without sudo ),it ...
0
votes
1answer
42 views

Expect Rsync with Double quotes

Below is my code: #!/usr/bin/expect -f set timeout -1 spawn rsync -arvz -e 'ssh -p 1690' --protect-args --progress /home/pappu/ 'backup@xx.xx.xx.xx:/volume1/56 - Backup Server/pappu' expect "password:...
0
votes
1answer
29 views

Shell Scripting - double condition with two variables

Good morning folks, I have to do this for my class assignment and I don't quite grasp how to. The script will ask the user for two separate statements which will fill two variables, L and C. I need ...
0
votes
1answer
30 views

Running an X application from a shell script via systemd timer

I'm trying to create a systemd (user) timer that opens certain tabs every day at 9PM with xdg-open. Here are the files: /home/me/.config/systemd/user/test.service [Unit] Description=Test [Service] ...
0
votes
1answer
27 views

update lines in a file

I have a file,where it has some fields.For example, var One = "fcb"; var Two = "abc"; How can I update/replace these lines using a script? I want to be able to do something like : echo -n "...
0
votes
1answer
32 views

how to keep oldest file in same directory

I had 2 directories "../in/" and "../temp/".My question is how to write bash script to keep the oldest file or directories in same ../in/ directory and remaining files or directories are moved to ../...
1
vote
1answer
27 views

run pm2 from remote shell script

I am trying to write a script which ssh into a bunch of my servers and runs some commands to start my app. One of the commands (pm2) always says pm2: command not found. This is how I'm attempting this:...