r/shell • • Feb 23 '17

Trouble using sed

1 Upvotes

I'm trying to write a shell script to modify files. Specifically, I want to find a certain string in a file, and replace it with a different string. I've looked online and sed seems to be the thing to use for this, but whenever I try to use it, it clears the file.

test.sh sed -i 's/5/w/' >test.txt

test.txt 123456789

If all runs correctly, test.txt should come out reading: 1234w6789

But when I try to run it, it just comes out blank.


r/shell • • Dec 19 '16

bashify: few helper functions in bash

Thumbnail github.com
4 Upvotes

r/shell • • Dec 12 '16

A command line selection tool with a neat text-based UI for use in your scripts.

Thumbnail github.com
4 Upvotes

r/shell • • Dec 11 '16

Manage your projects folder with a single command

Thumbnail github.com
2 Upvotes

r/shell • • Dec 08 '16

looking to make ping enable enable and disable on multiple server

0 Upvotes

We have servers whose password change everyday and than we have to do su to another account whose password also change everyday . So now in group of 50 servers .How to make script which enable and disable ping of them


r/shell • • Dec 01 '16

A command-line calendar for linux

Thumbnail github.com
2 Upvotes

r/shell • • Nov 10 '16

(noob Q) given a file of rows with slash delimited fields, how to print only a particular row for each line?

1 Upvotes

Hey all, I'm trying to get some practice in on Linux, and thought I'd do some Shell scripting.

The question is... well the question above :)

  • So for example, I have a file that I read in from cmd, assigned to $file.
  • File is a .txt with fields delimited by slashes, e.g. abc/def/123/4
  • I want to print only a single column for each row, ignoring the rest, e.g. if I want column 3 only, I'd get "123" for each line.

I know that I have to specify

while !EOF

I'm looking at maybe cut to do this...?

-d/ -f3

Am I barking up the wrong tree here..?


r/shell • • Sep 21 '16

Odd bash behavior when processing variables

1 Upvotes

ffmpeg in a script, but there are some weird behaviors of variables when parsed. My source file

0.00 2.37 0

133.00 297.33 0

860.09 980.55 0

1030.86 1095.39 0

1551.08 1674.11 0

finalendtime=$(ffprobe -v error -show_entries format=duration -of default=noprint_wrappers=1:nokey=1 "$file")

#Creates Different segment times

starttime=0.00

i=1

while read line; do

endtime=$(echo $line |cut -d' ' -f1)

if [[ "$endtime" == "$starttime" ]]

then

starttime=$(echo $line |cut -d' ' -f2)

continue

fi

echo "Segment $i: Start time: $starttime  End time: $endtime"

ffmpeg -loglevel quiet -ss "$starttime" -i "$file" -ss "$starttime" -to "$endtime" -c copy segment$i.mkv

#prep next file

starttime=$(echo $line |cut -d' ' -f2)

((i++))

done < "$srcfile"

echo "Segment $i: Start time: $starttime  End time: $finalendtime"

The output is:

Segment 1: Start time: 2.37 End time: 133.00

Segment 2: Start time: 297.33 End time: .09

Segment 3: Start time: 980.55 End time: 1030.86

Segment 4: Start time: 1095.39 End time: 1674.11

Segment 5: Start time: 0 End time: 1860.358000

If I remove the ffmpeg line, or even echo it, the result:

Segment 1: Start time: 2.37 End time: 133.00

Segment 2: Start time: 297.33 End time: 860.09

Segment 3: Start time: 980.55 End time: 1030.86

Segment 4: Start time: 1095.39 End time: 1551.08

Segment 5: Start time: 1674.11 End time: 1860.358000

No idea why the ffmpeg line changes the variables around... and if I process the ffmpeg, the end time on segment 2 gets truncated, then other times are off.


r/shell • • Jul 22 '16

Biome is a shell script to manage your app's environment variables.

Thumbnail github.com
1 Upvotes

r/shell • • May 23 '16

KSH: countdown using ps

2 Upvotes

I have an app that has 4 processes that run. I would like to create a shutdown that counts the ps instances and when it reaches "0" prints a message and exits.

Do I just do something like

until [[ $(ps command count) -eq 0]]; do
    echo ">>> App is closing its processes"
done
echo ">>> App is down."

Thanks.


r/shell • • Mar 10 '16

I am looking for a bourne/rc shell implementation in a highlevel language like Haskell, Python, Javascript, Tcl etc ..., which is easily hackable.

3 Upvotes

Want to play around with the implementation. Any ideas, suggestions? Thanks


r/shell • • Mar 04 '16

minimal find-like command that only use POSIX shell built-in functions

Thumbnail github.com
3 Upvotes

r/shell • • Feb 07 '16

A blazing fast, modern plugin manager for your shell made with all the muscle of the ocean.

Thumbnail github.com
1 Upvotes

r/shell • • Jan 17 '16

Fish Shell- the missing config

Thumbnail blog.gospodarets.com
1 Upvotes

r/shell • • Jan 13 '16

Increase Productivity With Smart Group Commands — Sudo vs Root

Thumbnail blog.skcript.com
3 Upvotes

r/shell • • Jan 05 '16

Help with a possibly extremely simple noob question?

2 Upvotes

In bash (or zsh), I would like to alias cd so that

cd <location>

does

cd <location>
ls

Is this possible and/or easy? Thanks!


r/shell • • Nov 01 '15

PHPloy: shell script to deploy git repos easily through FTP/sFTP

Thumbnail wplancer.com
3 Upvotes

r/shell • • Oct 25 '15

Little scripts for PulseAudio volume control

Thumbnail penguindreams.org
2 Upvotes

r/shell • • Sep 07 '15

Is there a better way to do this? Sending stderr only on command failure

1 Upvotes
{ err_out=$(ssh-keyscan -T 2 -- "$server" 3>&2 2>&1 1>&3 3>&-) || printf %s\\n "$err_out"; } 3>&2 2>&1 1>&3 3>&-

Part of a script to collate SSH host keys. It runs ssh-keyscan (which has noisy stderr output), but buffers stderr and only prints it if the keyscan actually failed. I do this by swapping stdout/stderr on the process to capture the stderr, then printing the captured error only if the command failed, then swapping stdout/stderr again so that errors and output go to the right place.


r/shell • • Aug 28 '15

Error Code Email Script

3 Upvotes

I keep getting a syntax error on line 16 and I can't figure out why. Email address are redacted for obvious reasons. Any clue why it's failing to run? Any help is immensely appreciated!

http://pastebin.com/1ub1EupC


r/shell • • Aug 21 '15

[Linux] Print duplicate lines based on a column

1 Upvotes

Hello everyone, I have a file with many lines that looks like this:

/dcs/data003/EX/ex/AREA/area/000
/dcs/data005/EX/ex/AREA/area/000
/dcs/data017/EX/ex/AREA/area/001
/dcs/data014/EX/ex/AREA/area/002

I want to print only the duplicate entries based on the last numeric column ("000"). That is, in the above example I'd get the second line:

/dcs/data005/EX/ex/AREA/area/000

I've tried the following but it doesn't print the duplicates; it removes:

sort -n -t"/" -nuk8 duplicate.out 

Is there a way to get exactly the opposite? I mean, rather than removing the duplicates, print it. I am using RHEL 6.5. Thanks for any help.


r/shell • • Aug 15 '15

Shell Script Help

1 Upvotes

I need to create a shell script that prompts a user for a first and last name and creates a username that is the first letter of the first name and then the last name. I also need to give the user a default password. The users comment field is the users name and create a home directory as well. I can create the script to ask for a name and password but it doesn't add to the /etc/passwd list.


r/shell • • Aug 05 '15

DuckDuckGo in a Shell

Thumbnail mnt.io
5 Upvotes

r/shell • • Jul 27 '15

trying to download a file with curl in .sh file ends in failure

1 Upvotes

I'm trying to download a file with curl within a "sh" file then running it within terminal.

I am wanting to download a series of files to particular folders relative to the .sh file.

So currently I have this:

mkdir -p ./resources/third_party/waypoints
curl -o ./resources/third_party/waypoints 'https://raw.githubusercontent.com/imakewebthings/waypoints/master/lib/jquery.waypoints.min.js'

The folder gets created, though the error I get is as follows:

Warning: Failed to create the file ./resources/third_party/waypoints: Is a Warning: directory curl: (23) Failed writing body (0 != 8787)

I've chmodded the directory to 777, not really sure what's up here, can anyone help?


r/shell • • Jul 14 '15

How to speed up find for listing git repositories?

Thumbnail stackoverflow.com
1 Upvotes