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

learn more… | top users | synonyms (2)

1
vote
3answers
108 views

How to delete a line with variable search using sed command

I am new to sed. What is wrong with the sed command on deleting the line which matches the input data? InputData.txt 123, 1234, 1453, Datatodelete.txt 1234,hellofirstline 123,hellosecondline ...
0
votes
0answers
54 views

bash script to check zabbix java gateway

I wrote simple script to check status of a service and when service is down search live processes for the service and kill them, then remove pid file and restart service. The problem is that the ...
21
votes
7answers
823 views

Should scripts that require sudo fail if they don't have it, or use sudo and prompt?

I have a script which gives me fine-grained control over my backlight brightness and requires sudo to run. It's essentially this: backlight="/sys/class/backlight/acpi_video0/brightness" echo $1 | tee ...
3
votes
6answers
119 views

Will $0 always include the path to the script?

I want to grep the current script so I can print out help and version information from the comments section at the top. I was thinking of something like this: grep '^#h ' -- "$0" | sed -e 's/#h //' ...
0
votes
2answers
47 views

How to search '(+1)' character substring in a string

I want to search for (+1) in a string (which is a GDG dataset name to confirm if it is a GDG) and want to get a binary answer if it has (+1) as part of the string or not. Can some one please help?
2
votes
2answers
72 views

redirecting to /dev/null

I'm reading an example bash shell script: #!/bin/bash # This script makes a backup of my home directory. cd /home # This creates the archive tar cf /var/tmp/home_franky.tar franky > /dev/null ...
1
vote
3answers
47 views

Executing bash shell scripts

I am reading an article on executing bash shell scripts. Method 1: Create a directory for your shell scripts and add the directory to the contents of the PATH variable, so that you can execute the ...
3
votes
1answer
666 views

What's the difference between “==” and “=~”?

Given a string and a hash returned by openssl, why using == doesn't match them correctly but =~ does? Background question: How can I force a script to use more resources?
2
votes
2answers
38 views

Script to Recognize HDDs and run Smartctl

I'm thinking to do a script to recognize which HDDs are in use (sda, sdb, etc) and run a Smartctl on each one that's are in use, but I don't know how can I start, anyone can help me?
-2
votes
2answers
72 views

how to get particular port number using shell script? [closed]

RABBIT_PORT=$(netstat -tupln | grep beam) echo $RABBIT_PORT Output : tcp 0 0 0.0.0.0:47858 0.0.0.0:* LISTEN 4533/beam tcp6 0 0 :::5672 :::* LISTEN 4533/beam I want to extract the ...
3
votes
5answers
171 views

How can I force a script to use more resources?

I'm running a very time-consuming script which takes many hours to end. Watching top I see that it's only taking 5% of the CPU at best, usually around 3%. Is there any way to force the script to use ...
-4
votes
3answers
146 views

How to get IP Address using shell script? [duplicate]

Want to get the IP address using Shell script. Without knowing the eth0 or eth1 or eth2 How to get the particular IP address. I am not interest to get localhost address, want to get private IP ...
-4
votes
4answers
90 views

How to add a 3 lines in a file using shell script? [closed]

I have a file, that file contain 10 lines. And now I want to add 3 lines to end of the file using shell script. After add lines, If I run the script again I don't want to add same lines again. ...
2
votes
4answers
126 views

Bash script to output path to USB flash memory stick

How would I return (output) the path to any USB flash memory stick(s) connected to the local computer using bash (Ubuntu and Linux Mint)? Background: I'm providing users with an automated backup ...
1
vote
5answers
72 views

Command for display of Memory usage, Disk Usage and CPU Load

I want to diplay the Memory usage, Disk Usage and CPU Load in the following format: Memory Usage: 33/512MB (6%) Disk usage: 4.2/20GB (23%) CPU Load: 0.01 How can I do that?
4
votes
4answers
139 views

How do I make sure that a script is run exclusively? [duplicate]

So I have a bash scripts that does some things (pull from github, delete folders .. etc ..) pretty basic stuff. I usually run it whenever I need a new version of the web app on the server. The thing ...
0
votes
2answers
79 views

How to write an alias function to make dd show progress bar?

According to this article, by replacing: $ dd if=/dev/sda of=/dev/sdb [additional options] with: $ pv -tpreb /dev/sda | dd of=/dev/sdb [additional options] one can augment the default dd ...
7
votes
7answers
927 views

cron Vs. sleep - which is the better one in terms of efficient cpu/memory utilization?

The Case: I need to run some commands/script at certain intervals of time and for this I have two options - 1. set up a cron-job or, 2. implement a loop with sleep in the script itself. Question: ...
1
vote
0answers
55 views

Better approach to generating and adding contents to files

I have an input file like below. 1 First one 2 First two 3 First three 3 Second three I am generating 2 output files like below. #FILE1 1 First one 2 First two 3 First three #FILE2 1 ...
0
votes
0answers
33 views

How to install libevent tmux?

I've been trying to install libevent / ncurses / tmux into '$HOME/local', but am having an issue running .configure for tmux. What I am trying to do is install it as follows: TMUX_VERSION=1.8 ...
6
votes
4answers
316 views

Check if $REPLY is in a range of numbers

I'm writing a shell script for Linux, using Bash, to translate any video-file into a MP4. For that, I'm using avconv with libvorbis for audio. Inside my script, I have a question for the user : ...
2
votes
2answers
50 views

How to list all the files which were not created on Thursday

I need to delete old backups but I only want to keep Thursday Backups and delete the rest of the backups. Give me some kungfu tips. I'm on RHEL if that makes a difference.
0
votes
2answers
136 views

Are there any well known and well used shell scripting IDEs for Un*x?

Are there any IDEs targeted at shell scripting, specifically bash and zsh scripts? This means having syntax-highlighting for shell scripts and more importantly debugging environments with features ...
1
vote
1answer
29 views

Creating shell script on Desktop and not getting a prompt?

I have created a shell script on Desktop. Whenever I open it , I get a prompt to either run in terminal, display and etc. How to remove this prompt?
2
votes
1answer
66 views

Find out if files in a folder exist under other name in other folder

Possibly a little incorrect English ahead: There are at least 2 folders. For this, A contains files without extension, usually usernames, and B contains similar files, with '.yml' extension or ...
1
vote
2answers
77 views

What's the difference between print and head?

I know head gives you the beginning section of a file. But in this case, I'm trying to go through my source control and find every file that has a shebang line. And I'm failing to get results when I ...
1
vote
0answers
83 views

shell script to check if process is running [closed]

I want to implement a shell script in Ubuntu that checks if process is running. If not, I want it to launch existing byobu (screen) session 1, and then run the command "mygateway" which will run the ...
-1
votes
1answer
43 views

Remove directory without `rm -r`

How to remove non-empty directory without using rm -r or find -delete ? I think it is related to unlink, perl or inode
1
vote
3answers
164 views

How to loop a read function in Bash Script?

I needed to remove spaces and capital letters to various strings of text like: "My Name is Mauro" -> "my_name_is_mauro" So I have created this bash script:lowercase_underscore.sh (call it the ...
6
votes
3answers
258 views

Remote ls on multiple machines

I want to connect to multiple machines specified in a file and perform 'ls' there. That's what I've come up with: for machine in $(cat machines) do echo "Connecting to " $machine ssh $machine ...
9
votes
2answers
853 views

Fastest way to concatenate files

I've got 10k+ files totaling over 20GB that I need to concatenate into one file. Is there a faster way than cat input_file* >> out ? The preferred way would be a bash command, Python is ...
3
votes
1answer
69 views

chmod + silent mode + how force exit code 0 in spite of error

Is it possible execute chmod and ignore error from command Example ( remark file.txt not exsist to show the example ) When I type chmod 777 file.txt I get error on the output chmod: cannot ...
0
votes
1answer
62 views

is there a “goto” like command in ksh

Here is my script: #!/bin/ksh #this is where I want to go again if user enter #an answer other than "yes or no" echo "yes or no?" read ans case $ans in [yY]*) echo "yes" ;; ...
2
votes
2answers
112 views

Shell script works when saved with nano but not when saved with Notepad++

I've been working on a bash script all day and have been testing on the machine I will be using it on. When I copy the script across from Notepad++ into a new file with nano editor inside SSH and ...
1
vote
2answers
56 views

Script always runs two instances

I was just curious, what may be the reason why script run two instances when executed. Whenever I run my script foo.sh, and when I check using: $ ps -ef | grep foo.sh It always returns two ...
1
vote
1answer
94 views

How can I use a loop inside a command?

I'm writing a shell script that contains a command that takes multiple directories as space-separated input arguments (like ls). I would like to fill in those arguments from a variable but don't know ...
-2
votes
2answers
81 views

Input validation in a bash script [duplicate]

I've got the basics of bash scripting (I think anyways), and i'm trying to move on to more advanced stuff. I am trying to write a script that will perform input validation (the user must input either ...
0
votes
3answers
72 views

remove new lines

My input is a csv file like this: 10,"Special Projects,bangaram",0,,0 10,"Statutory/ Internal Audit , MO reporting (incl Excel Spreadsheet uploadation) ", bangaram,0,,0 10,"Complience with ...
1
vote
2answers
121 views

Creating a shell script that parses and redirects number into next command?

I am trying to create a script that kills an Xorg process. Here is an example of me running the commands in a terminal: First, I find the process id of the Xorg program (in this case, 2494): . ...
3
votes
1answer
109 views

shell Script: Sorting files into directories and subdirectories

I routinely write my notes in markdown in a complex directory structure like this. ~/doc/doc.md ~/doc/math/linearAlgebra/linearAlgebra.md ~/doc/math/linearAlgebra/numericalAnalysis.md ...
4
votes
4answers
498 views

Check for Process if Same is Running

Is there a script or a way in linux that when I try to execute a shell script/process, if the same is running, it will prompt that same is running and will exit otherwise it will continue.
-2
votes
2answers
108 views

how to execute a python program in a shell script

I have a python program in that I wrote some python code (disk.py). I executed this program using the command python disk.py in a terminal, it worked. Now I want to execute it using a shell script.
0
votes
1answer
28 views

Capture Error of LS to file [duplicate]

#!/bin/sh if [ $(ls sample01.log | wc -l) = 1 ] then echo "File Found" > lsOutput.log else echo "File Not Found" > lsOutput.log fi But if sample01.log is not already existing my code already ...
4
votes
1answer
65 views

measure amount of data read from /dev/random

background I have written a collection of bash scripts (most of them in German only yet but if you are interested; download the archive not the single scripts) which help users create high-quality ...
3
votes
3answers
363 views

Adding a Column of values in a tab delimited file

How can I add a Column of values in a file which has a certain number of rows. I have a input file like this: Input file: SPATA17 1 217947738 LYPLAL1 1 219383905 FAM47E 4 77192838 SHROOM3 4 ...
2
votes
1answer
52 views

bash script - need date command variable

I am trying to create a script that will parse the /var/log/secure file for failed login attempts for today's date only and redirect those attempts into a separate file so I can view those attempts ...
1
vote
5answers
76 views

Replace instance of process in place?

I suspect this is not doable just because of the security implications, but here's what I'd like to do. Basically we run a bash shell-script on our CentOS server that calls Program-A (in our case ...
1
vote
3answers
141 views

What does “FILENAME=$(echo $INFILE | grep -oE ”[^/]+$“) ” mean?

FILENAME=$(echo /root/Source/code/script.sh | grep -oE "[^/]+$") I know that it would give me the file name from the file path here as script.sh. But can some one please explain me this?
0
votes
1answer
35 views

How to write simple if condition in ash?

I would like to write a small script that would check every once in a while if I have the internet connection. I would like to run it in crontab on my router where I have ash. I am having a hard ...
-1
votes
2answers
14 views

Shell script to format logs

Requirement : I need to write a script to find out for which API the request has been sent but no response received. Given below is an example of the logs i'll be working with. 2014-02-28 ...