Tagged Questions

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

learn more… | top users | synonyms (2)

-1
votes
3answers
31 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
35 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
71 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
102 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
49 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
26 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
201 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
10 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
34 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
41 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
49 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
171 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
49 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
36 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
30 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
46 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
53 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
43 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
29 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
28 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
144 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
56 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
21 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
138 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
22 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
67 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 ...
13
votes
3answers
629 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
21 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
218 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
49 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
33 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
81 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
488 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 ...