Tagged Questions

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

learn more… | top users | synonyms (2)

0
votes
1answer
8 views

awk - Why does $var give the value of $0?

I have written a very simple awk script that reverses every word of a file-: awk ' { for (i=1;i<=NF;i++) { x="" for(j=length($i);j>0;j--) x=x substr($0,j,1); print x }}' file1 The contents of ...
0
votes
0answers
22 views

Bash Graphical uninstaller using a tool to make graphical my script [on hold]

I have a problem with logic on this part of my script, I can't see my fault. . Basically the script must be do the follow: 1 - Ask if you wanna uninstall 2 - Check if the "$PATH_TO_SOFTWARE" ...
0
votes
0answers
15 views

Bypassing the security message in Debian 7 when creating a bash script? [duplicate]

I've created a bash script which involves the installation / update of wget. As a result there is also a message from Debian showing the following: wget (1.13.4-3+deb7u2) stable-security; ...
1
vote
0answers
25 views

Ubuntu runuser command?

I am creating a bash script that requires to run commands as a specific user. As a result I am using the command: runuser I have tested this script and it works perfectly in Ubuntu Server 14.10. ...
0
votes
2answers
38 views

Percent signs and environment variable in a shell script

While troubleshooting an issue, I came across these entries given below in one of the shell scripts used by our application. This was written by someone who no longer works in the company and I am ...
4
votes
5answers
137 views

Calling multiple bash scripts and running them in parallel, not in sequence

Suppose that I have three (or more) bash scripts: script1.sh, script2.sh, and script3.sh. I would like to call all three of these scripts and run them in parallel. One way to do this is to just ...
1
vote
2answers
36 views

Why double ampersand chained conditions runs in background together the last one?

I have some conditions for some background job to run: condition-command && condition-command && background-job & The problem is: I want the conditions to block until the job ...
0
votes
3answers
40 views

Group by and sum in shell script without awk

I have a file like: $ cat input.csv 201,100 201,300 300,100 300,500 100,400 I want to add the values in column 2 which has same value in column 1. Expected output is as follows: $ cat output.csv ...
1
vote
2answers
36 views

disk space by individual user

I have around 50 user folder under etc/main/ folder. Now i want to get 10 large space user folder detail. Note: I don't want sub-folder of each user..I am using Ksh script. Example: /etc/main$ ...
0
votes
0answers
9 views

Running a script with elevated privileges [duplicate]

I need to find a way to run a script with elevated privileges but without compromising security. One suggested that i should use setuid but i don't think that is an option since it can cause serious ...
2
votes
2answers
76 views

How to read from a named pipe after the writer process exits?

I want to use named pipes as asynchrnonous task queues (JMS-like, perhaps). For example, suppose a client sends some data that I wish to insert into a database, but I want the client to disconnect ...
2
votes
2answers
107 views

Negative arguments to head / tail

Variants of this question have certainly been asked several times in different places, but I am trying to remove the last M lines from a file without luck. The second most voted answer in this ...
0
votes
1answer
54 views

sh script cannot run process

I have fairly simple sh script that checks if process is running, if not then start it. My problem is that sh script cant start the program for some reason... Here's my script: #!/bin/sh if ps x ...
0
votes
1answer
27 views

How to Trim below highlighted lines from Shell output

How to Trim below highlighted lines from Shell output. Source shell program is below the output. $ ./checkhome.sh The Oracle base remains unchanged with value /opt/oracle Connecting ...
2
votes
3answers
204 views

Bash File existence test is always true

I have the following lines of bash script to test whether a file exists: MYAPPPATH=$(find $APPDIR -iname myapp* -print) if [ -e $MYAPPPATH ] then echo "File exists" fi However when file ...
0
votes
1answer
11 views

How to script with systemd-cgtop?

The manpage for systemd-cgtop says that if there is no attached tty it will do one iteration and then print it out, saying that this would be useful in scripts. However when I try to do this from a ...
3
votes
1answer
35 views

Split input file into X parts of size total lines / X

Currently, my bash script splits by number of lines. However, I'd like to split a file into X pieces, each of those having total lines equal to the file length divided by X. The script is run as ...
1
vote
0answers
40 views

Cron can't access my home directory when I'm logged out

I have quite a strange problem using cron. I distilled it thus far: I created following simple bash script in /home/user1/cron_dir/cron.sh: #!/bin/bash echo "Success" As user1 I created following ...
2
votes
2answers
47 views

Inputting user input automatically through bash script? [duplicate]

I am creating a bash script which creates a user and sets a password. When the command "passwd user" is run it requires the user to enter a password and stops my script. Is there any way to fulfill ...
1
vote
1answer
50 views

Sh Script using ftp to put a list of files

So my Script looks something like this: #... files="$(find $line/processed/* 2>/dev/null)" #2>/dev/null used for error output suppression if [[ ! -z "$files" ]] then ...
1
vote
1answer
174 views

How to get owner and full path of 50 large size file across all users?

Below command list top 50 files regardless of subfolders. $ls -lR /root/home | sort +4 -5nr | head -50 Current Result: -rw-r--r-- 1 john dpst 192954384 Nov 7 07:36 filenxx1.gz ...
-4
votes
0answers
26 views

script to get login details of employess [on hold]

a company owner wants to check which of his employees are on time and are late. WASS for getting the login details of the employees.
1
vote
1answer
29 views

Is there a way using a bash script to get the location of changes made in last git commit?

I need to check the location of the files, which were changed in the last commit. Because I will have to do this on Jenkins, this should be done using a bash script. This is the output of git ...
1
vote
3answers
50 views

Generate networking configuration files using sed and bash

I am a bit rusty on my scripting abilities and am trying to find a good starting point for creating a script that creates files (generating new file names) and edits the IP address in the file by ...
0
votes
2answers
37 views

how to insert backslash at the front of # symbol?

In bash programming, given a variable, say varA, that store a string containing # symbol. Let's assume varA contain this value: ASD# 1, I need to append a backslash \ at the front of #, so the output ...
0
votes
1answer
33 views

How to ssh and execute a remote script within a local shell script?

I have a shell script which will kick off a series of jobs on a remote server. I can ssh into this server (but it does require a password!) and run the scripts manually, but there are certain steps ...
1
vote
2answers
47 views

syntax error in conditional expression

I am writing a script where I am using the combination of logical 'OR' and logical 'AND' statement. This is the script: #!/bin/bash echo "Enter the value of a" read $a echo "Enter the value of b" ...
2
votes
2answers
56 views

syntax error near unexpected token `<'

I am writing a script to read the output of a command to variable a and b. This is the script #!/bin/bash read a b < <(awk '/Application Server/ && !seen[$7]++{printf "%s ", $7}' ...
2
votes
1answer
44 views

What is the most portable syntax for `if` statements?

(NOTE: There is a very similar question, asked yesterday oddly enough, but it doesn't cover the main syntaxes I'm concerned with. If I were to update the other question to include them it might ...
-1
votes
0answers
26 views

Count valid upper case alphabetic letters by using read command

I need to write a script. Bu using read command, take set of upper case alphabetic letters, one at a time. The input end with a 0. Display the first letter in alphabetic order among all the valid ...
2
votes
3answers
41 views

How to open terminal, split to 9 terminals and switch between them using one script?

I would like to open a terminal, split it to lets say 9 parts (3x3) and execute some bash script. But for each terminal part different script. Can this be done using perl, python or even bash? How ...
0
votes
2answers
43 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
30 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
16 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
30 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
146 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
30 views

Script working properly in all iterations of for loop but first iteration [closed]

The script below commands code in run_real_$dd.sh to be run for each number in the for loop range. The code produces the output files: wrfinput_d01 and wrfbdy_d01 for each iteration. For the first ...
0
votes
0answers
57 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
22 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
31 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
42 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
140 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
45 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
120 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
23 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
11 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
43 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
91 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
73 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 ...