0
votes
1answer
51 views

Can you have a terminal file in Linux like windows Batch? What is the extension?

It has been a while since I downloaded my Kali Linux on a Windows virtual machine (VirtualBox not VMware). On my Windows host I have created numerous batch scripts that can execute "cmd code" with a ....
0
votes
0answers
7 views

How to forcefully stop an endless loop in Upstart “pre-start script”?

I have the following pre-start script in one of my Upstart configurations:pre-start scriptcd "$(dirname "$(dirname "$(readlink "/etc/init/${UPSTART_JOB}.conf")")")". "lib/upstart/waitFor[...]....
0
votes
2answers
27 views

splitting up a file: substitute `egrep` in `sed`

I want to split my $file containing x lines in half, and check how many lines contain "dead" in a log. I started off with the following:half=`expr $(egrep -c . $file) / 2`sed -n 1,${half}p $file |...
0
votes
2answers
44 views

Bash :: append text to output of file

I am very new to Shell Scripting so this maybe a very easy solution but i'm struggling to get it to work.I have a file with this content:example1.eu example2.eu example3.euWhat I am trying to ...
2
votes
1answer
49 views

Cannot scp Over a Shared Connection

I am having the following problem with an SSH shared connection:# Set up a shared connectionssh -f -N -M -S "$SSH_CONTROL_SOCKET" root@"$ONE_HOST"# I can scp *without* the shared connectionscp ...
2
votes
2answers
28 views

Check if Filename is of Form <filename>.<md5sum of file content>

In Bash, how can I most easily check that the filename of a regular file is of the format shown below?<filename>.<md5sum of file content>For example, assume I had a file whose original ...
3
votes
1answer
42 views

Redirect input from code or terminal to running code or terminal?

Currently, I am using a software script that requires continuous input through the terminal. The script evaluates files continuously by receiving path input and evaluating the file in the path. The ...
0
votes
1answer
170 views

read command with timeout for non-terminal input in bash

The read command in bash is used for user input. Option -t N invokes the timeout of N seconds. But, as mentioned in the man page, This option has no effect if read is not reading input from the...
1
vote
1answer
99 views

Getting AWK error while transpose some message content

I trying to transpose below text into single line with pipe separated, i getting some error if text is start with number% , what is the issue, any other command is there Sample content in txt file...
0
votes
0answers
26 views

ssh-copy-id works in one direction only

I have a script that until two weeks ago was working between a file server and a host server that was backing up a tar file using rsync. I used ssh-keygen to generate the keys successfully on the ...
1
vote
2answers
37 views

What is the purpose of having a boolean expression containing an exit code in this shell script?

I have a problem which is solved by this answer http://superuser.com.xemphimonlines.com/a/508761Now I need to expand on it to do other stuff but first I need to understand better how it works before modifying it. ...
5
votes
2answers
861 views

Write n bytes from a file into another in Bash

Hello how can I write n bytes from one file into a new file starting from the k position using Bash?For example if n=60, k=1 and file size=100 then: the 2nd file would consist of from the 1st byte ...
0
votes
1answer
103 views

What are pros and cons of using && or || versus if/elif/else?

In bash, I can make a test condition utilize && and/or || rather than an if/elif/else block. When applicable, I use tend to use && and/or || rather than building out an if block. Are ...
1
vote
4answers
59 views

Rotate odd numbered pictures

I write a little script to rotate all the odd numbered pictures of a directory but i can't get it to work. Here is the code.#!/bin/bashcount=1for picture in `ls -v *.png`doif ["$picture"==...
-1
votes
2answers
387 views

How to: concurrent cURL downloads?

How can we use curl to download several files concurrently? Even if we need to spawn multiple curl processes, how can I do it from command line or shell function? For example:$ multiCurl <...
0
votes
1answer
107 views

How to interpret curl timeouts?

curl --max-time 3 'http://website.com';if [ 0 -eq $? ]; then ...else...fiI'm trying to have curl respond differently to URL's that timeout. How do I pass the output of the curl ...
1
vote
1answer
192 views

Find files but exclude several directories?

How do I use find to list every single file but exclude a handful of directories from the search?find / -type f -not -path "http://superuser.com/foo*" -not -path "/bar*" -printI've seen examples on other ...
6
votes
1answer
648 views

Bash variables with space (directories)

I'm trying to echo all of the files in /foo while preserving the spaces within listed directories. Currently, a directory titled "bar1 bar2" will echo out as /path/to/foo/bar1/ then /bar2 then file....
4
votes
3answers
383 views

What is wrong with this while loop?

BackgroundI have created a script to:Read a list of ip's one at a timeCopy a config file from local host to remote hostReboot remote hostClose current ssh sessionContents of script:#!/bin/...
0
votes
2answers
20 views

How to manipulate two possible arguments?

I use my custom script ccc to compile .c files like this:g++ -std=c++11 -Wall -pedantic -Wno-long-long -Wshadow -g -o "${1%%.c}.out" -lm "$1"Basically I use ccc main.c and then main.out comes out. ...
-4
votes
2answers
82 views

Reading input by bash [closed]

In the bash doc there is a statement:The shell reads its input from a file, from a string or from theuser's terminalCan You provide some examples of each of these 3 options?
1
vote
1answer
391 views

Remote Execution of a Shell Script that Takes a Local File as an Input Parameter

Using Linux, bash, and OpenSSH, I can execute a shell script on a remote host in at least three ways:# Method 1: Script is never stored on the remote hostssh <username>@<hostname> 'bash ...
0
votes
1answer
52 views

How to calculate the output of screen -ls?

all. How can I write all sessions into an array? (screen -ls)i.e: 23257.name_session1 (06/25/2017 10:41:18 PM)(Detached) 22011.name_session2 (06/25/2017 07:50:33 PM)(Detached)arr[0]=23257....
1
vote
0answers
70 views

Bash: Return output from a command when a file is read

I have a Java application running on customer systems that receives OTA updates when the system is connected to internet. The customer has a utility that reports the current version of all the ...
0
votes
1answer
17 views

How do I copy all files from one directory into matched files of another?

For exmaple I have 2 directories with the following structuresDirectory 1http://superuser.com/img/1.jpghttp://superuser.com/img/2.jpghttp://superuser.com/img/3.jpghttp://superuser.com/img/4.jpgDirectory 2http://superuser.com/thumb/1.jpghttp://superuser.com/thumb/2.jpghttp://superuser.com/thumb/3.jpgHow do I copy only ...
2
votes
1answer
772 views

How to change/add a tracker to a .torrent file using the command line?

I use transmission-daemon on Debian for my torrents.For now, I've been using the website http://torrenteditor.com/ to add trackers to .torrent files.I'd like to edit .torrent files directly using ...
1
vote
0answers
279 views

Which bash rc files are run on non-interactive/non-login shells?

My Understandingthere are no rc files called for non-interactive/non-login shells; for example, those run by cron(I don't know this for certain and would lean on the community's expertise)non-...
0
votes
1answer
130 views

show duplicate data with awk print $2,$3,$4 in a single line

If I have a 2 lists that contain the following (examples):list1x;00:26:82:50:00:00;192.168.1.195;COMPUTER1x;00:26:82:50:11:11;192.168.1.195;COMPUTER2x;00:26:82:50:22:22;192.168.1.196;COMPUTER3...
0
votes
1answer
378 views

Script to move or unpack files (rtorrent when finished script)

The conceptSo I´ve been struggling for a while now with a script that will run when rtorrent has finished a download. The script should check the third argument from rtorrent and act accordingly.....
0
votes
2answers
214 views

How to use current filename multiple times in a pipe command?

I'm trying to convert batch of .mov files to mp4. How can I get filename from pipe to generate ffmpeg command? How to use pipe argument multiple times in the chain link?I'm trying to have something ...
0
votes
1answer
71 views

Running x11vnc contigency

Essentially I have this bashname(start)#!/bin/bashx11vnc rfbport subport && x11vnc rfbport main portsource /home/Desktop/prime.sh;name(prime)#!/bin/bashx11vnc rfbport mainport...
1
vote
1answer
60 views

For Loop not printing the required result

I am trying to use for loop in my script.I have ssh into a server and moved to the respective directory. Insidethe directory I have multiple files.I wanted to loop through each file.the files ...
0
votes
0answers
18 views

How can I automate an install with numerical options?

For instance, if I was installing a package with apt-get, I would do:sudo apt-get install -y PACKAGE_NAMEbut in this case, my options when I manually install will be '1', '1' and '2' respectively. ...
3
votes
1answer
111 views

Passing Optional arguments to Grep

I am using grep to exclude lines containing certain strings.The command I am using is cat VlanConfig.txt | grep -vE $1\|$2\|$3I want to keep the $3 as optional argument.It should accept two or ...
0
votes
1answer
195 views

Script for using AesCrypt on a lot of files

I'm just learning bash and I'm about to renew my backup security standards at home, just in case something happens.I have two external HDDs for Backup. I want to encrypt the files first on my laptop ...
0
votes
2answers
203 views

Bash script not creating files when run by clicking

I have a bash script that runs a program which generates files (into the current directory it was run from), then the bash script checks for them, and their sizes.When I run this script from the ...
0
votes
1answer
709 views

How to filter 'cat' output to only display a portion of text?

I'm trying to find a way to filter the output of a cat command to only display the text included between two points. I need to put this on a script.More to the point, given the following sample text...
0
votes
2answers
111 views

sed - Function to replace only the NTH occurrence

In the function below (f_ez_sed) I would like to just replace the "NTH_OCCUR" (0~n) occurrence. How I could do that? I have tested MANY methods!f_ez_sed:f_ez_sed() {: 'Facilitate the use of "...
3
votes
2answers
2k views

How to grep multiple lines from a file in linux

I have a file with the below content...hello...world..hello.....world..the dots indicates the other lines in the file. Here what I need to gerp only the lines hello and world. ...
1
vote
2answers
106 views

Bash Script, Striping out newline characters in variable

Still getting the hang of bash scripting...I have a function that resizes images and calculates how much to scale it based on the file size. I need to pass this percentage as an argument to the ...
-2
votes
3answers
762 views

How can I write a bash function that checks if an integer is even or not?

How can I write a shell predicate function event that takes an integer argument and tests if it's even or not?
0
votes
1answer
516 views

Bash loop for adding --exclude list to tar

I have a bash script I made to encrypt/decrypt using GPG and tar. Right now I have my --exclude hard coded into the script, but I'd like to make it a bit more dynamic and add the items to exclude as ...
0
votes
2answers
1k views

using sed in BASH script: replace text with info from system variables (hostname and date)

I want to use a bash script to run a backup and then send me an email using ssmtp. I am trying to make a generic script that I can reuse across different Linux machines. Below is a snippet of the ...
1
vote
2answers
839 views

Running script that has sudo commands with sudoers

I wrote a script that helps clean up my downloads and anime, but it won't run without root. So I tried adding it to /etc/sudoers (edited using techraf's suggestions):# This file MUST be edited ...
0
votes
1answer
35 views

Tar compress directories and contents into individual, dated files based on folder name bash script

This is on a Debian system.I have had the compression of files and contents into individual folders working fine but not with the date added to the file names.Removing the date part, it works as it ...
0
votes
1answer
27 views

write a variable to a file on the end of a specific line

I want to add a variable to the end of a specific line in file file.txt. My code so far:#!/bin/bash read -p "What is the path of the repo? > " inputecho :$input >> file.txtI want it ...
2
votes
1answer
11k views

How to mail output of shell script as a cron job

I've created a cron job that runs a shell script. I'd like the shell script to run and capture it's output and have it emailed upon completion. Here's what I have so far, but the mail message body ...
0
votes
1answer
2k views

“line 3: syntax error near unexpected token” in a shell script

I am trying to run some executable with parameters several times. I wrote a script for it. But I am always getting an error and can't figure out on how to fix it.#!/bin/bashexport VCF_FILE='...
0
votes
2answers
90 views

How do I ssh into a machine and cat a file on that box simulteanously?

Basically I want to remotely cat a file, this is what I have so far. It doesn't work. I'm fairly new to all this:echo /root/.ssh/id_rsa.pub | ssh root@HOSTNAME "cat >> /root/.ssh/...
1
vote
4answers
1k views

cat all files except a select few

If there some particular syntax so that I can cat all files in a directory, except for the select ones. For eg., suppose I have ~1200 text files containing some lines, about 3 or 4 lines per file, ...

153050per page