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

learn more… | top users | synonyms (1)

-1
votes
2answers
23 views

how to get the return value of wpa_supplicant?

My question is really simple I want to get the return value of the command wpa_supplicant, when connected to the internet, to know that I am connected or not with a shell script.
4
votes
2answers
109 views

Convert every pdf in the current directory to png

I want to write a bash script to convert every .pdf file in the current directory into a .png file. For example: $ls . a.pdf b.pdf $./pdf2png.sh Converting pdfs to pngs a.pdf -> a.png b.pdf -> ...
4
votes
3answers
85 views

How to read user input in pipe?

Let's assume I have a file named confirmation.sh with the following content: #!/bin/bash echo -n "Are you sure [Y/n]? " read line case "$line" in n|N) echo "smth" ;; y|Y) echo "smth" ...
1
vote
1answer
63 views

For loop not getting executed correctly over ssh

I have a script in which I am reading from a csv file where it contains SourceIp, DestinationIP,Source Ports, Destination Ports. First I am reading the sourceIp and trying to do ssh over it (I am ...
2
votes
5answers
287 views

How to reverse a string made of digit in bash?

What is the best way to turn out digits in number? E.g. $ echo 123 | hook 321 $ echo 12358 | hook 85321
2
votes
1answer
30 views

gnome-open execute shell script

Is there a way to execute shell scripts automatically using gnome-open? If I call gnome-open script.sh in the terminal, the script opens in the default text editor. However the shell-script is ...
3
votes
2answers
40 views

Bash script : help file inside the script or in a different file?

I'm writing a script that has the vocation to be a fully featured program at the end. As far as I know, BASH is enough for his purpose (manage PPA's, kinda like Y-PPA). I would like to know how to ...
1
vote
2answers
44 views

Bash script is not working

I wanted to create a script that executes the ls command with the provided arguments. Why isn't it working? I tried running it with for example -R, then it echoes (I echoed the same thing for ...
2
votes
2answers
50 views

I want a script which will take multiple column numbers from a user and reverse the contents

I want a Unix script which will take multiple column numbers from the user and reverse the contents. declare -a param="$@" # enter 0 when exit the insert element echo "Enter the numbers" read n while ...
11
votes
4answers
1k views

How Does Linux deal with shell scripts?

For this question, let's consider a bash shell script, though this question must be applicable to all types of shell script. When someone executes a shell script, does Linux load all the script at ...
2
votes
1answer
87 views

Bash Script getting stuck during execution

I have a bash script that is reading a CSV file , that contains source IP address , destination IP address and destination port. My script is basically doing 2 tests: 1 Performance 2 Connectivity. ...
4
votes
3answers
193 views

Check if 2 directories are mounted on the same partition on Linux

How can I check if /my/dir is on the same partition as /? This is for integration within a script. Bind mounts should be handled correctly. POSIX compatible solutions are welcome.
2
votes
4answers
99 views

Parsing process command-line arguments from pargs in a shell script

I get list of PIDs in my bash scripts (Java processes) and have to analyze their command-line arguments to determine which instance of server each PID corresponds to. At the moment I do it that way ...
0
votes
3answers
67 views

I want to create a zipped output file while keeping the original one

I am new to unix command and I have got one scenario that, I want to create a zipped output file while keeping the original one. I want to do it from Informatica end by using command task or session ...
1
vote
2answers
69 views

Supply input to a program with a password prompt

Is there any Linux command which supplies multiple enter keys to another process which is running in a terminal till the other process dies? For example consider the command yes ' ' | ./ssr-sim ...
1
vote
3answers
93 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
47 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
811 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
116 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?
1
vote
3answers
42 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
665 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
36 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
66 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
170 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
126 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
83 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
112 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 ...
0
votes
2answers
77 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
893 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
53 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
30 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
256 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
49 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.
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
65 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
78 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
42 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
6
votes
3answers
256 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
837 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
60 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
60 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
108 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
54 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
92 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
71 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
120 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
103 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 ...