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

learn more… | top users | synonyms (2)

4
votes
6answers
179 views

Finding the number of time a particular number in a file where range also specified

I have a file with numbers separated by ,(comma). In between it also contains a number range like 300-400. Say for example I have a text file, namely testme.txt which looks like, ...
2
votes
1answer
64 views

Asteriks in filename as wildcard not working [closed]

So I have a folder with many files like 20140720.457812.tmp and I try to count how many lines they have, I tried this: #!/bin/bash lines=`more /folder/20140720*.tmp|wc -l` but I get this error: ...
4
votes
3answers
106 views

Frequency of words in non-English language text: how can I merge singular and plural forms etc.?

I'm sorting French language words in some text files according to frequency with a focus on insight rather than statistical significance. The challenge is about preserving accented characters and ...
1
vote
1answer
38 views

Formatting an external HDD with Bash script

At my workplace we have an external HDD connected to a NAS device (Synology). There is a backup tasks which runs weekly and fills the external HDD after a while. Unfortunately the Linux-based OS of ...
0
votes
0answers
48 views

How to find the cpu and memory usage of a single process in linux

This question is similar to this SO. I wanted to find the CPU and memory utilization for a single process so I decided to use the top -p <$PID> as mentioned in the question. Here is my script. ...
2
votes
1answer
29 views

What do I need in my script to be able to change ownership of a directory structure that belongs to root to the current user running the bash script?

My bash script has the following section: su root -c chown -R smithb:other /export/home/smithb/workspace/rootownsit/ exit The directory rootownsit and its two sub directories were created and is ...
5
votes
1answer
62 views

How to continue a script after it reboots the machine?

I'm writing a shell script in bash. At some point in the script, it detects that the machine needs to be rebooted before continuing. It issues: sudo reboot When the machine comes back up, there ...
0
votes
0answers
20 views

A script to identify whether a file descriptor has gone bad

Problem : I have a server program running which connects to a remote program using TCP sockets. There many of them (say 20). My problem is one of the socket descriptor has gone bad and has recieved ...
2
votes
2answers
56 views

How do you construct a grep & command to match a number of patterns depending on how many are provided at runtime?

I have exported some MS Word documents to plain text and use this function to parse the contents of the .txt files in the current directory: mo1 () { for i in *.txt; do echo "File: $i" grep ...
2
votes
1answer
41 views

How can I get this script file's functions to load without having to source it every time? “command not found” (Bash/scripting basics)

How can I get this script file's functions to load without having to source it every time? I created a file foo with script functions I'd like to run. It's in /usr/bin, which is in the PATH. File ...
1
vote
2answers
44 views

Copy ssh public key to multiple Linux hosts

I am trying to copy .ssh/id_rsa.pub from our central server to multiple servers. I have the following script which I usually use to push changes to the different servers. #!/bin/bash for ip in ...
3
votes
1answer
34 views

Restricted ssh remote execution with arguments

I need to enable remote execution of a shell script on a server, but deny all other access. The script is a toggle that accepts a single parameter (on/off/status). This comes close to answering my ...
11
votes
3answers
428 views

Comparing two strings in Bash

I have the following if block in my bash script: if [ ${PACKAGENAME} -eq kakadu-v6_4-00902C ]; then echo "successfully entered if block!!" fi The script execution is not entering my if block even ...
1
vote
1answer
19 views

Create bash script for wine cmd script

I have installed FIFA09 through wine & it runs great...however i have to manually go to installation directory each time & open the terminal there. Then have to write in two steps: wine cmd ...
1
vote
2answers
45 views

Tmux Split Panes in the same window

I am new to using tmux in scripting and I am attempting to manipulate it so when I run a script I can have multiple screens attached and split in my Putty session, and also have it color coded and ...
2
votes
1answer
56 views

How to terminate a shell script?

I'm working on a supercomputer and have a shell script that will automatically schedule a bunch of jobs for me. Once the script is run, I can terminate manually with Ctrl+C. I was running the script ...
2
votes
3answers
132 views

sed + remove the first directory from path

Please advise on how to remove the first directory from a path by sed, (the inverse pf what basename does). For example echo "/mnt/VPfig/Amer/AR4/Celtel/files/COM.txt" | sed ... I should get: ...
2
votes
3answers
48 views

adding list of users to multiple groups

I have a shell script which add list of users which is listed in another file lets say users.txt. After that, I want my script to add users to multiple existing groups with condition, one user may ...
1
vote
2answers
43 views

Creating Menu list and Executing the Task

I was given the the Task to create a menu in Linux but it appears it's not coming out great. When I select something I want to be able to perform that task then go back to the main menu when I finish. ...
1
vote
1answer
31 views

how to use the eval command in order to print the value of parameter

Please advice how to use the eval command in order to print the parameter value for example bash a=1 b=2 c=3 for i in ` echo a b c ` > do > echo "$i=` eval $i ` " > done bash: a: ...
0
votes
4answers
31 views

Bash one liner to change configuration parameters

I have a config file with following structure. ValueOne = 1 ValueTwo = 2 ValueThree = 3 I want a one liner bash script to find ValueTwo and change the value to 22222. Any idea? Not School Thing
1
vote
4answers
58 views

Compare two numbers read from a file

I have a script that reads a file with a standard format where the 9th word is a number. I am trying to compare the number that is read from the file. I am able to read the line correctly and it works ...
5
votes
4answers
525 views

generate consistent machine unique ID

Can we generate a unique id for each PC, something like uuuidgen, but it will never change unless there are hardware changes? I was thinking about merging CPUID and MACADDR and hash them to generate ...
0
votes
1answer
43 views

Parse lines of output from bash loop

I'm trying to parse the output of commands run in a bash loop. Here is an example: $ for i in `git log --format='%H'`; do echo $i ; git branch --contains $i; done | head -n 8 ...
5
votes
1answer
597 views

Why do I have to escape a “dot” twice?

I know that we can escape a special character like *(){}$ with \ so as to be considered literals. For example \* or \$ But in case of . I have to do it twice, like \\. otherwise it is considered ...
4
votes
1answer
161 views

sudo: unable to execute ./script.sh: no such file or directory

I'm stumped. I have a script in my /home directory which is executable: [user@server ~]$ ll total 4 -rwx------ 1 user user 2608 Jul 15 18:23 qa.sh However, when I attempt to run it with sudo it ...
0
votes
1answer
24 views

How to dynamically chose PBS queue during job submission

I run a lot of small computing jobs in remote cluster where job submission is managed by PBS. Normally in a PBS (bash) script I specify the queue that I would like to submit the job through the ...
2
votes
0answers
93 views

Securing a script a little more

I currently have the following script which works fine: #!/bin/sh user="$(zenity --entry --title="Username" --text="Username")" pass="$(zenity --password --title="Password" --text="Password")" ...
0
votes
1answer
29 views

Reusing user input in a script

I have the following script which works: #!/bin/bash xfreerdp /cert-ignore /f /v:farm.company.com /d:company.com /g:rds.company.com /u:$(zenity --entry --title="Username" --text="Username") ...
0
votes
1answer
62 views

Bash script question - skip enter key press [duplicate]

Here is a portion of my script: read main_menu case "$main_menu" in "0" ) exit ;; "1" ) cp /etc/bamt/cgminer.conf.X11 /etc/bamt/cgminer.conf; sudo mine restart; ...
1
vote
1answer
36 views

Bundling of dependencies with shell scripts

Shell scripts often have to depend on tools that may not be installed on the users' computer. To circumvent this problem, many scripts have multiple fallbacks. IMO doing such things only leads to ...
3
votes
1answer
63 views

Convert json numbers to strings in the shell

When parsing json, the command-line tool jshon converts numbers to scientific notation, and sometimes tries to round them. To avoid these problems, I want jshon to consider these numbers as strings. ...
2
votes
1answer
44 views

Bash Script Permission denied & Bad Interpreter

I'm on a kali linux 64 bit. I have created a python script which takes 2 arguments to start. I don't want to type out every time the exact same paths or search in the history of the commands I used ...
2
votes
2answers
109 views

How to force watch to run under bash

The problem is that when watch is executed it runs sh and I get this error: sh: 1: func1: not found here is the code: #!/bin/bash func1(){ echo $1 } export -f func1 watch func1
5
votes
3answers
210 views

How to extract URIs from files

How can I extract from a certain number of files all the URIs like magnet: file:? I'd like to have one URI per line as the output. I'd like to use bash to achieve this, but any suggestion is welcome. ...
4
votes
5answers
233 views

Delete the last character of a string using string manipulation in shell script

I would like to delete the last character of a string, I tried this little script : #! /bin/sh t="lkj" t=${t:-2} echo $t but it prints "lkj", what I am doing wrong? Thank you in advance!
3
votes
3answers
139 views

Pipe in a shell script

I have done this little script : #! /bin/sh path="foo" while touch $path ; do path=./${path} done echo "echec avec le nom $path qui fait" echo $path|wc -c echo "caracteres" How can I ...
2
votes
1answer
58 views

SSH config file + shell script help

Well, what I want to do seems a bit convoluted but its the only way I can think of to get the result I want. So here goes. I want to automate ssh to my Pi, in the following fashion: My Pi boots up ...
1
vote
0answers
7 views

Automating minisat solutions

I'm a unix noob and need a simple (bash) script. I am solving SAT instances using minisat. The syntax is minisat inputfile outputfile. However, it only returns one solution. To find all solutions I ...
4
votes
1answer
58 views

Communicating from bash with grunt shell

I'm tired of the slow startup time of hadoop fs just to query HDFS. This isn't a problem with HDFS itself though, because using HDFS file system commands within the Pig "grunt shell" is pretty fast. ...
0
votes
2answers
100 views

If UID=1000 continues, else exit

I am wondering how to implement the following in a bash script. if UID=1000, continue else exit confirm choice (y/n)
0
votes
1answer
37 views

elif [ “$input” = “no” ]; then go the next statement

#!/bin/bash input="" echo "Does a wall needs to be sent?" read input if [ "$input" = "yes" ]; then echo "Sending message to all user about a system reboot or shutdown"|wall elif [ "$input" = ...
0
votes
1answer
40 views

Syntax error in bash script: near unexpected token `else' [closed]

#!/bin/bash input="" echo "Does a wall needs to be sent?" read input if [ $input="yes" ]; then echo "Sending message to all users" echo "" else if [ $input="no"]; then exit fi fi echo ...
3
votes
2answers
42 views

Filtering images according to file name, why?

When filtering the images using the below code, I also need to filter files. For example,IMG_0079.JPG.JPG, when running the code below it's allowing files with additional .JPG to get filtered out, ...
3
votes
3answers
43 views

Moving latest files from one directory to another

I'm trying to move newest files from one directory to another directory. The find command finds the files but not moving them to another directory. The destination directory exists. $ cd ...
1
vote
1answer
85 views

Why does this script work on Ubuntu, and not Debian?

I run a simple minecraft server. I made a script awhile ago for Ubuntu that would automatically create a Gnu screen and start said server. I decided get a new server with debian instead. Now for some ...
3
votes
2answers
29 views

Comparing an string by value of a floating number to a number

I wrote the code below: for j in `cat output_10.txt` do dri=`echo $j |cut -d':' -f1` nu=`echo $j |cut -d':' -f2` tot=`echo $j |cut -d':' -f3` fre=`echo $j |cut -d':' -f4` if [ $fre > 2 ] ...
1
vote
1answer
23 views

How to slice a text file into several files of 100 lines each? [duplicate]

My question might be quite unclear here. I have a giant text file with values that looks like this 0.00601233 0.000139403 0.000133679 0.000139497 0.000141683 0.000141888 0.000138646 0.000133465 ...
3
votes
1answer
30 views

Why does the read command not take interactive options when run by sh?

I want to download a provisioning script that reads some configuration parameters via read, and execute it: curl http://example.com/provisioning.sh | sh The problem is, that the read command in the ...
3
votes
2answers
132 views

using “ifne” in Bash pipe

In my script, I am using the ifne utility from the moreutils package. The line can be simplified to the following: printf "asdf\n" | ifne cat - && echo "stream not empty" ifne only ...