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

learn more… | top users | synonyms (2)

0
votes
3answers
78 views

What is the most concise script to list the missing ones in a digit sequence? [duplicate]

For example, we have the content 001 002 004 008 010 in a text file named file, how to extract the missing 3 5 6 7 9?
0
votes
1answer
37 views

xterm no absolute path found for shell

I am trying to run a script in SUSE Linux Enterprise 12 from java using ProcessBuilder. Codes for this follows: ProcessBuilder pb = new ProcessBuilder("xterm", "-e", "script_path"); Process pr = ...
1
vote
2answers
69 views

Using special character " and ` in send command in expect script

I am trying to execute a command in Linux servers to fetch which all servers requires root password reset as there are multiple servers I am using an expect script to automate it , my command contains ...
0
votes
0answers
26 views

script to change an option and show it in a selection

I need option 2 to display Run myscript when you select option 2 I want it to run my script can anyone help me
3
votes
3answers
112 views

Bash: Convert a string (version number) to an integer

I want to get the version of glibc and use it in an if statement stating if glibc is less than 2.15 then. However the issue is that when using the ldd --version this is output as a string. i need to ...
1
vote
1answer
52 views

Is there a way to resolve ALL PIA VPN IPs with a script?

I am looking for a way to get a complete list of all the current IP addresses for PrivateInternetAccess' servers. I need the complete list so that I can manually enter them into a killswitch for ...
2
votes
0answers
13 views

Using a web browser to generate a gallery/slideshow from local files

I'm trying to see how far I can go with using a web browser for various tasks vs. native apps. One of these tasks is selecting a group of local image files and generate a preview/gallery/slideshow in ...
1
vote
1answer
45 views

Why don't the SHA's match?

I am trying to write a script and it uses the SHA of a date but I am getting two different results and for the life of me can't figure out why. echo -n 03112016 | cut -d'.' -f4 | sha256sum | cut -d' ...
1
vote
2answers
68 views

Rename files in a directory

I have the files names as below in a directory example1.1.timestamp(.1457644337) example1.2.timestamp example1.3.timestamp and so on about 100 files. I need to rename all the files by removing the ...
1
vote
0answers
39 views

Assigning floating point value to array in Unix shell script loop [closed]

I am using ksh scripting on Ubuntu 14.04 and am trying to write a script to add floating point numbers to an array. My code is as follows numLoops=6 numerator=14996288 denominator=1000000000 for i ...
-1
votes
3answers
70 views

Shell scripting : want to login on some server, which are in same domain and execute command and exit

I have 10 unix servers, I want to log into them one by one, execute 4-5 lines of code, save the output and exit. For Example: 10 serves: Intially at xyz server Login in server 1 --> execute 4-5 ...
1
vote
1answer
74 views

What do \t and \a mean in a shell script?

What do \t and \a perform or do in a script? For example, I am writing a script and it goes like this \t it displays a simple script \a
1
vote
2answers
42 views

getting the owner of the folder with the if command [closed]

i want to be able to prevent people from accidentally deleting critical files of the system in my my script, does anyone know how to use the statement to find if the owner of the folder?
0
votes
1answer
615 views

Is the xkcd universal install script a good idea? [closed]

Today XKCD posted this shell script: Alt-text: The failures usually don't hurt anything, and if it installs several versions, it increases the chance that one of them is right. (Note: The 'yes' ...
1
vote
2answers
63 views

make a shell script to be run as a second user

I am making a script where I wish to run two services as a certain user. The script should switch to a user and then run a program and after the program has been executed, it should start running the ...
-1
votes
3answers
65 views

Better way to parse string with bash?

I need to parse the below command to extract namespace & interface names using a bash script. I generally do this using IFS, but that seems tedious to me. Is there a better way of doing this ...
3
votes
3answers
61 views

How can I remove just the writable files in a directory, without any prompt?

I want to delete only the writable files in a directory. If I do rm * it removes all the writable files (so far so good), but I get a prompt for each non-writable file. I don't want a prompt, I ...
0
votes
2answers
56 views

Can I have a (bash) shell with expect running in the background?

I am trying to write an expect script that once started will watch my terminal and run a command every time that it finds a match. Is this even possible with expect? If so, would expect_background ...
2
votes
4answers
60 views

move a file that matches a pattern in a shell script

I have very little experience in writing shell scripts and need advice on how I can accomplish the following task. I need to move the most recent file in a directory where the filename matches a ...
3
votes
1answer
103 views

Delete lines from a file

I have a file where data is present in below format : cat file.txt 02|123 04|321 08|453 09|364 01|789 23|765 so here 02,04 ... represents Hour and 123,321 ... represents some random value. I want ...
0
votes
0answers
26 views

How I compare multiple file results and then using its file result execute the next command?

I run a sql script through atable to insert data from one T1 to T2 (total 8 tables). I am doing row counting between two tables if counts match then it returns 1 else 0 and stored result ('1' or '0') ...
0
votes
2answers
27 views

shell scripts when exceeding 100 seconds to send an email

When executing show engine innodb status on mysql, there are lines like ---TRANSACTION 17610C9A, ACTIVE 504 sec starting index read. I need a script to monitor for when the number of seconds after ...
1
vote
4answers
52 views

Remove any occurrence of '-' from a field in shell script

below is my csv file,I want to remove all occurrences of - from retailer_id field and create new csv. Kindly help... ...
0
votes
1answer
31 views

command line in su - and background

I am writing a simple unix script to automate reading of a log file. The following does not give any output to the terminal. It just asks for the password for buser and then it just hangs. I ...
0
votes
2answers
49 views

Compare a file with a column of another file

I have a file File1 with data as aaa bbb And another file File2 with data as: 2,aaa,234 w,bbb,589 4,ccc,675 I need to compare the File1 data with column2 data of File2 and print the matching ...
3
votes
1answer
67 views

VAR=`cat file` and then repeating echo “$VAR” is slower than repeating cat file. Why?

There are about 10.000 files in files/ and 10.000 lines in metadata.csv. Where metadata.csv contains information about the files. I have a shell script which prints information about each file and ...
1
vote
2answers
85 views

How to repeat prompt to user in a shell script?

In a set of if/elif/else/fi statements, I have made 'else' present the user with an error message, but I also want it to take the user back to the question which was asked before the if/else ...
0
votes
1answer
31 views

Impossible to write files with root credentials

I'm trying to launch a small script which fixes a bug in iceweasel icons. Here is the script. You can find it as a workaround in the bug report for n in 16 32 48; do inkscape -z -w $n -h $n -e ...
0
votes
2answers
68 views

How to use cd command in su command?

In the below script the cases aserver and bserver work fine. But in case "cserver" above, after su - gsxuserp, I need to perform the following three options with the same user. cd .. cd ...
2
votes
2answers
78 views

Sorting ls output where files end in numbers [duplicate]

Here is the output of my normal ls command: f1 f10 f11 f12 f13 f14 f15 f16 f17 f18 f19 f2 f20 f3 f4 f5 f6 f7 f8 f9 So I have 20 files. I need them displayed as : f1 f2 f3 f4 ...
1
vote
1answer
53 views

Sed command usage without defining variables in shell script

I have two variables source_repo="fdl_ppe_01_04_repos_svc" target_repo="fdl_ppe_01_10_repos_svc" and I currently do a substitution within an XML file to replace all instances of $source_repo with ...
1
vote
3answers
54 views

Return an exit code without killing caller's terminal?

I'm having a hard time getting the return value from a script. The script that is giving me trouble is second.sh below. But there's an interaction present with a script called first.sh, and that ...
0
votes
1answer
48 views

Trouble with Screen Rotation Script

I am running Antergos linux with Gnome 3.18.2 on a Dell XPS 12 Convertible laptop/tablet, and am working on making the screen rotation more convenient. I pulled a version of the following script from ...
1
vote
2answers
60 views

set -u usage not working as expected

I am learning how to efficiently use different set options in my script and came across set -u that appears to be perfect for exiting my script if a variable does not get set properly (ex. deleting ...
0
votes
1answer
64 views

-r filename && . filename

i was just looking into a script i find this line. can anyone tell me what this line do. this is the code line. [ -r "$PosConfigDir/posconfig.sh" ] && . "$PosConfigDir/posconfig.sh"
0
votes
1answer
44 views

Extract a specific part of the path of a file

Taking this path to a file: words/05_díj/díj_pct.txt how I can extract only this part? 05 What I want is to use that part as a value for an external variable for the execution of an awk script. ...
0
votes
1answer
61 views

Parse numbers with delimiter - BASH

I would like to parse ports, for instance 45:68. I defined testing var. echo "ports" read in I splited ports to array: IFS=":" read -ra port <<< "$in" Ports must be less than 65535, ...
0
votes
1answer
47 views

Verifying output of a command not quite working via BASH script

In attempting to verify if a remote database exists or not, I'm seeing mixed behavior with a conditional statement. Technically the statement is working (it correctly reports if database is found), ...
4
votes
1answer
113 views

Launch a sudoed command upon script termination?

I'm coding a bash script that: runs some sudoed command at initialization releases root permissions for security purposes (sudo -K) runs an unprivilegied program but needs root permissions when ...
1
vote
1answer
65 views

Untar File.tar.gz from Shell w/Nested .tar

I am trying to untar a file from a shell script. There is one file within the file.tar.gz that is a tar that is not getting untared. I have tried several methods with no luck. ...
0
votes
1answer
26 views

Make exported path effective immediately?

I'm using a script to export a path like this: echo "export MONO_PATH=~/turbo/" >> ~/.profile; So from now on, the path will be available whenever the user logs in. However, I want to the ...
-1
votes
3answers
71 views

How to catch with RegExp first word with different first symbol in it using ed text editor

I have shell command: printf '/^PermitRootLogin/\nc\nPermitRootLogin no\n.\nw\nq\n' | ed -s /etc/ssh/sshd_config And I need catch #PermitRootLogin like PermitRootLogin but not commented paragrath ...
4
votes
5answers
201 views

How shrink test -eq expression with more than one var value in /bin/sh

#!/bin/sh if [ $num -eq 9 -o $num -eq 75 -o $num -eq 200 ]; then echo "do this" elif [ $num -eq 40 -o $num -eq 53 -o $num -eq 63]; then echo "do something for this" else echo "for other do ...
1
vote
2answers
60 views

Copy Files Based on Dates in Filename

I am having an issue when attempting to copy a range files from one directory to another based upon a date contained within the filename. The date in the filename is in UTC whereas the created dates ...
0
votes
1answer
28 views

copy a directory into multiple directories

I have structure like A directory dir_a/dir_b and dir_c/dir_d to dir_z or some other 100 names. now I need to copy dir_b into dir_d and all other sub-directories in dir_c. And a part from that ...
3
votes
1answer
34 views

reformatting command output within bash script

within script the attempt here is to remove the : and then revert the / to \ within the print out currently I have to display the linux path: The home directory is located here: ...
1
vote
2answers
61 views

shell stderr to /dev/null

I have PID file and I want to get PID number so this is what I am doing. [root@linux ~]# PID=`cat /usr/local/foo/var/run/foo.pid` [root@linux ~]# echo $PID 3414 sometimes this file doesn't ...
0
votes
3answers
75 views

If, elif and else shell script Linux statements

#!/bin/bash echo "Type in your username in lowercase letters" read user #sudo adduser $user echo "Are you a student or teacher?" read group if (("$group"=="teacher")); then #sudo usermod ...
1
vote
0answers
43 views

CSV copyscript not copying 5 files out of 4000+

I was provided a great bit of code for searching and copying files listed in a csv from a directory and its subfolders in an answer to my previous question. However, some files are not copied. The ...
0
votes
1answer
83 views

text to xls file creation

I have 4 text files in my unix system want to put data into a xls file and send it via mail. text1.txt: 100 150 130 120 110 text2.txt: 200 230 240 250 260 .. .. .. so on ... I want to have ...