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

learn more… | top users | synonyms (2)

0
votes
2answers
55 views

How to list files and directories of a mount point

Given a mountpoint such as /dev/sda1 how can I list the contents of this file system using shell script. My objective is to delete the oldest file in this drive.
1
vote
0answers
37 views

How to select an option from a select menu from a script?

I'm working on a script to automate a fill tasks that I do hundreds of times a day, such as building iOS/Android projects, but I'm not very experienced with shell scripting. In one of the projects, ...
0
votes
2answers
23 views

Number of occurences of letters in a word?

I would like to find out the number of occurrences of each of the alphabets in a word. Eg input aabbbddd output a@2 b@3 c@0 d@3 How can I perform this using shell script?
1
vote
0answers
26 views

Start glassfish in LINUX server remotely

I want to start glassfish on a server running LINUX, the problem is that my service provider does not grant access to ssh connections nor any other helpful tool to run asadmin start-domain I have ...
1
vote
1answer
75 views

Rename bash script - false no such file or directory error

I am trying to rename a few hundred files based on another file in the same directory. I found a script and with modification I have the following: while read file; do echo mv ...
4
votes
3answers
160 views

Change case of n-th letter in a string

I want to change the case of the n-th letter of a string in BASH (or any other *nix tools, e.g. sed, awk, tr, etc). I know that you can change the case a whole string using: ${str,,} # to lowercase ...
0
votes
0answers
63 views

Strange bash sytax error depending on sudo usage

I made this bash function to detect if the user running is actually logged in as root user and not using sudo by checking the uid + home directory of the user executing the command: #!/bin/bash set ...
0
votes
1answer
28 views

regexp in find to locate only

I have csv file (products.csv) with product numbers $ cat products.csv | head -3 2.20 2.21 2.22 in another directory I have thousands of product images in subdirectories. I need to locate product ...
0
votes
2answers
44 views

Can't use argument in bash date calculation script

The following bash script won't work. I need to calculate the date depending on the number of days since 14th Oct 1582, where the argument will be the number of days. d="$1" date -d '14 Oct 1582 + ...
2
votes
1answer
50 views

Printing filled shapes in terminal

I'd like to print some shapes filled with the current color or a selected one (e.g. \e[31m) My aim is to print a filled circle (letter o) on the screen but the background will stay as it is. finally ...
3
votes
2answers
170 views

Bash - echo line by line, ignoring the space between the lines

I had read the post on: bash - replace space with new line, but it does not helped to solve my issue. [My Directory] [root@testlabs Config]# ls Archive Backup_Files config_file.tgz ...
0
votes
2answers
63 views

Bash getting integer expression expected

I have following script to check disk usage #!/bin/bash # set alert level 90% is default ALERT=10 OIFS=$IFS IFS=',' storage=$(df -H | grep -vE '^Filesystem|tmpfs|cdrom' | awk '{ print $5 " " ...
1
vote
3answers
136 views

for loop for running a command for all files in a folder

Suppose I have a folder which contains a lot of audio files. How can I write a for loop so that for each file audioname.mp3 in the folder, these commads are run: convert -size 300x200 xc:lightblue ...
1
vote
1answer
39 views

BASH - Command not found - LVM over LUKS Automation Script

I've been working a bash script to automate the process of opening and closing an LVM over LUKS external hard drive. However I continue to receive errors on line 28: $(vgchange -a n ; cryptsetup ...
0
votes
2answers
19 views

Autostarting Conky Weird Behaviour

I've set conky to be started after logging in by creating the file conky.sh in /usr/local/bin, and adding the entry conky.sh to the Xfce startup applications list. conky.sh contains the following ...
2
votes
2answers
45 views

Distance of a command from a shebang?

A shebang (#!/bin/sh) is placed on the first line of a bash script, and it's usually followed on the second line by a comment describing what action the script performs. What if, for no particular ...
1
vote
3answers
117 views

Constructing URLs with a list of words and downloading from the URLs with command line

Suppose I have a list of words in a text file e.g: abstinence ; abuse ; academic ; accommodate ; accommodation ; accommodationist ; accomplice ; accomplish ; accord ; account ; accountable ; ...
2
votes
1answer
110 views

YAD - Terminate Bash Script

I'm using YAD to create a Yes or No dialog box in a bash script: yad --image "dialog-question" --title "Alert" --button=gtk-yes:0 --button=gtk-no:1 --text "Are you sure you want to do this?" If I ...
12
votes
3answers
726 views

Determining if a file is a hard link or symbolic link?

I'm creating a shell script that would take a a filename/path to a file and determines if the file is a symbolic link or a hard link. The only thing is, I don't know how to see if they are a hard ...
1
vote
2answers
23 views

Comparing value in same column and directing output to new column

I have my input file as DPortal=ECCN RemoteFile=4004_130122 0256 A02 141111 0940 29343414 11 110005 DPortal=ECCN RemoteFile=4004_130122 0256 A02 141111 2336 29843714 11 110006 DPortal=ECCN ...
3
votes
2answers
245 views

Shell script wrapper to prevent running command with no arguments?

There is program I use, say xyz, that has undesirable effects if I run the command bare with no arguments. So I'd like to prevent myself from accidentally running the xyz command with no arguments ...
1
vote
1answer
121 views

Script for login in multiple servers and execute commands and append output in one file

I got the task of logging into some 300 devices, execute the following commands and then copy the output into one file. I can use SSH as a login method and I can give a predefined username and ...
1
vote
2answers
37 views

Randomize arguments ( that hold color codes) from an array

I have the array (shown below) with arguments that hold color codes. The intended purpose of my script is to randomize those arguments when the user inputs "scriptname randoms Text" so that every time ...
2
votes
2answers
83 views

Typing text from a shell script [duplicate]

I'm new to shell scripting. I'd like to know if there's a command similar to "echo" for displaying text in a terminal, but instead of simply displaying it immediately, it actually types it, like if ...
8
votes
8answers
522 views

Grep for pattern at start or middle of a line

I'll start by saying that I think this problem is a little less innocent than it sounds. What I need to do: check for a folder within the PATH environment variable. It could be at the start or ...
0
votes
1answer
16 views

Loop across url with static tokens with Oauth

I need to write a loop where I need to pass a "token" (which is fixed) and a variable (i) in the url. Is there any way I can achieve that? I wrote the following code but it is not working. If I put ...
2
votes
1answer
58 views

How do I wait for all child processes but one to finish executing

I am starting a number of processes in the background of the scrip that I'm writing. I want to wait for some of them to finish before the end of each iteration of a for loop, but there is one process ...
3
votes
2answers
94 views

Finding missing value in text file

I have a text file with following data. Name Feature Marry Lecturer Marry Student Marry Leader Bob Lecturer Bob Student ...
0
votes
1answer
47 views

crontab not executing my script?

I added this rule to the bottom of my crontab * * * * * /root/test.sh It basically resets iptables so I can fool around. If I mess up I won't be locked out of my box. When I run the script in bash ...
0
votes
1answer
34 views

Check for subdirectory

A)I used the following code to get the modified date of a file. But this is also selecting the subdirectories and thus returning an error. How van I fix this. for file in $1/*; do echo `stat ...
3
votes
2answers
72 views

How do I perform the same set of commands within multiple subdirectories, in a numerical order?

Within my parent_directory, I have subdirectories labeled E-11_G, and E-10_G. Within each of those subdirectories, I have more subdirectories labeled E-2_U, E-1_U, and E0_U. In each of those folders, ...
1
vote
1answer
30 views

Search and remove with regular expression

How do you use regular expression in bash to search any given string and remove occurrence of particular word? This is the expression I've come up with ^([A-Za-z-]+)(-).*(el6.*)$ What I would like ...
6
votes
1answer
164 views

Function that calls another function with list of arguments doesn't work

In my .bash_aliases I have defined a function that I use from the command line like this: search -n .cs -n .cshtml -n .html SomeTextIWantToSearchFor /c/code/website/ /c/stuff/something/whatever/ ...
1
vote
4answers
117 views

How to subtract two times in shell

I nee to subtract two lines which is in the format of time in shell. Th time format is hh:mm:ss I used the code below to get the time. cat /var/log/kern.log |grep usb |tail -2| awk '{print $3}' The ...
2
votes
2answers
48 views

How to select unique array values?

I have an array and I want to get the unique 2nd members bash doesn't really have 2-dimensional array so I've defined it this way, using :: as the separator of the two elements: ruby_versions=( ...
-1
votes
1answer
48 views

Please elaborate the following script(5,7 lines)

#!/bin/bash # Declare array declare -a ARRAY # Link filedescriptor 10 with stdin exec 10<&0 # stdin replaced with a file supplied as a first argument exec < $1 let count=0 ...
1
vote
2answers
43 views

Shell, howto extract letters from $line1=“Test this… test this!”, and print one by one

I am writing a script, which I would like to spice up a bit. What I need, is a loop, which takes one letter at a time, including space, and then write it on the screen, like an old typewriter would ...
3
votes
2answers
64 views

Syntax error: word unexpected on io redirection on file descriptor ≥10

I have the following shell script on debian 7: #!/bin/sh case "$IFACE" in lo) # The loopback interface does not count. # only run when some other interface comes up exit ...
2
votes
3answers
58 views

How to process a while-do loop and sort the iterated output

I'm very new at Bash Scripting so forgive my ignorance. I have a text file with last names that I am reading and processing line-by-line an average of three test scores. I need to output the lines ...
1
vote
1answer
56 views

C Shell detemined the file

I'm very new to C Shell. I'm trying to read a file from the command line, and determine whether it's a zip file, a .txt, a symbolic link, a pipe, or whatever ("unknown"). Then I'd like to execute a ...
3
votes
1answer
77 views

Mirroring stackexchange including external images

This script will create a mirror folder with all my activity pages saved for offline reading including all affected questions #!/bin/bash USERNAME=rubo77 MAXDEPTH=2 # increase this if you want to ...
2
votes
0answers
55 views

Copy folders at once

I want to copy a large number of folders at once not one by one. Is it correct to use the following code ? Is it helping to run the command cp for all the folders i at once? #!/bin/bash foreach i in ...
0
votes
2answers
66 views

cat STDIN won't work twice in script

I have a script that outputs various information and the text fields of an html form (method POST). When I attempt to cat <&0, it displays properly. However a few lines down, I try to cat ...
1
vote
1answer
35 views

For loop for curling on multiple pages with API's

I am trying to crawl a website for fetching pages using an API. When I issue the command cd desktop/mysite ; curl -O https://api.mysite.com/info?page=2 I get the data on the desktop. Then I wanted ...
1
vote
1answer
52 views

how do I remove ./ from the file name

How do I remove ./ from the file name ./script 1 when entering it as a command. I want to be able to enter the command just as script 1 for it to run?
4
votes
2answers
253 views

Script working on Mac but not Ubuntu

The script executes on a Mac machine and creates the output file, although on an Ubuntu machine it generates error message. Bash shell is used on both instances.: 1 - /var 2 - /etc : 1 : bad ...
-1
votes
1answer
31 views

SMTP log anonymize script

I have a SMTP log with records in the format below: 6,222.3.4.5,3040,100.2.3.4,25,UNKNOWN,0,1,……,9337bc-929a-34c0-29a8-b3a89c834b29 ,protocol,SMTP ,745663746,STATUS-COMPLETE ,VALID ...
0
votes
2answers
109 views

Constantly check if file is modified bash

I have a file called file1 I want in a script, whenever there is a change in it, do something, a beep sound actually. How do I do that ¿? Thank you in advance
1
vote
4answers
69 views

How to use regex in sed?

I need to revoke the sudo access to the user using sed in scripts. I want to comment the user only if the line contains /bin/su - root Let us consider the file as below, in which I have to comment ...
0
votes
1answer
44 views

Shell script equivelent to PHP $_POST

For example and learning purposes, I have a webpage that uses POST method to submit a text field. I have a server running script (bash) that I want to display what the "Query_string" is. I'm not ...