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 [scripting]

A script is a sequence of commands or instructions that are executed by an interpreter program rather than compiled into a standalone executable program.

0
votes
1answer
17 views

control-flowed variable in Bash

The web-application document-root for Debian-Apache is typically /var/www/html/ but for Arch-Apache it's typically /srv/http/. I wrote a distro-agnostic LAMP-establishment script and I need it to ...
0
votes
0answers
16 views

How to generate (git) diffs with <n> characters of context?

The --unified=<n> option lets you set the number of lines; is there a way to do the same for characters? example limit the context around the changes to X character(s) when using git diff --...
0
votes
0answers
37 views

Shell script - directory size

I have to create a script that calculates the size of a directory given as an argument in bytes, like ./du.sh dir. Optionally I have 2 other arguments: ./du.sh dir 1000 files.txt, where 1000 stands ...
1
vote
0answers
13 views

How do I embed a JPG thumbnail to a ogg/opus audio file with a script? [duplicate]

I am using youtube-dl to download ogg audio files with their respective thumbnail, but I am not sure how to embed the thumbnail into the audio file. I looked at the potential duplicate: Add album-art ...
0
votes
2answers
36 views

Enter IP at the end of a specific line

I have the following file.txt that follows the same pattern and I want to modify it where this file is by adding an ip: # gfhfhgfh gfhfghgfhgfhgfh MACs # access USER CONSOLA *,!10.249.247.3,!10.249....
0
votes
1answer
22 views

Script “7 days log tar and then remove the 7 days logs and exclude the tar file after next 7 days”

I am trying to create a script such that it could tar.gz all the previous log of per 7 days log and exclude the tar file in next run. Is the script ok or should I have to make a change find /home/...
-1
votes
1answer
20 views

How to write a script to kill & clean the resources of executing process?

I have an application running in c language (my_process.c) and a script (stop_process.sh) to stop the application and clean up all resources held by the process. In the application code, let's say I ...
2
votes
2answers
68 views

import environment variables in a bash script

I set some environment variables in a terminal, and then run my script. How can I pull in the variables in the script? I need to know their values. Simply referring to them as $MY_VAR1 doesn't work; ...
1
vote
0answers
42 views

systemctl doesn't work from crontab

I'm trying to run a script calling systemctl from crontab but the command is not being executed. Other scripts work fine from crontab. The script works when executed in a terminal. This is the script:...
1
vote
1answer
21 views

Can I create BASH function that will hold text block that can then be called for output to FILE and SCREEN to cut down on code block repetition [duplicate]

I have a BASH utility that outputs measurements to screen live as it runs and writes the result to file at the same time. I am having to repeat the same code twice (see below). Once to write to ...
-3
votes
0answers
23 views

Download files from file list wget

I have a file where are written downloading links Google.com/image2 Google.com/image3 Google.com/image4 Google.com/image5 Google.com/image6 i want to download all of them with scripts. If the name ...
4
votes
2answers
328 views

Find only GUIDs in file - Bash

I have a file that might contain GUIDs (their canonical textual representation). I want to do an action for each GUID in the file. It might contain any number of GUIDs. I have already a file ready ...
1
vote
1answer
61 views

How to pass variable from one function to another function

updateEnvironmentField() { linewithoutquotes=`echo $LINE | tr -d '"'` b() } I want to pass variable named $linewithoutquotes to another method called b(), which is called from ...
1
vote
0answers
49 views

Rsync pull script? [on hold]

I need to make a Rsync pull script on my backup server from my rsync server running on: Rsync port: 873 Ip: 192.168.1.189 User: Rene Password 12345 Folder on Rsync server: / Myfiles-share It should ...
0
votes
0answers
27 views

After SSH not able to read the input from the keyboard and display on the screen

#!/bin/bash server=(*.*.*.*) echo "Connecting to IP : $server" ssh -i dotestnet root@${server} " echo "Present Working Directory : $pwd" echo "Deleting existing packages...." rm -rf ~/transactions rm -...
1
vote
2answers
52 views

Identify and email results

I want to identify files older than 180 days. I am doing this with: find *path* -mtime +180 -exec ls -la \; > file.txt The problem is, from this result set I want to send email to the various ...
1
vote
1answer
30 views

Login script that requires user to re-enter displayed random number string

I currently have a script that runs upon a user logging into a Linux server and at the end it prints [Terms of use agreement prints here] read -p "Agree and continue..." -nl -s However, most users ...
2
votes
1answer
35 views

Improving performance of Script Using find and exec [closed]

I have a script that iterates through a given directory and automatically compresses those that do not contain at least one file used in less than 30 days. Now, I am wondering if I could improve ...
1
vote
1answer
26 views

How to create a .deb package using the source code which would compile and install automatically when .deb is installed in different system

I have the source code and need to crate a .deb package. When it is installed.., it shld compile the source code and install the resulting binaries when the deb package is installed. I know creating ...
0
votes
0answers
10 views

Truncate from beginning in Rofi

I'm using this command for a rofi-locate script (source): xdg-open "$(locate $query | rofi -threads 0 -width 90 -dmenu -i -p "locate:")" Currently all long path results are truncated from the end, ...
2
votes
1answer
27 views

wget image problem for daily wallpaper script

i have a script (that Nuno wrote) to wget an image from one particular site and set my wallpaper. however i can't seem to modify it to be able to wget an image from this site: chromecast images in ...
1
vote
0answers
37 views

Running Telegram bot on Linux VM Azure [closed]

I am running a python Telegram bot on Azure, and it does not work at all. It does not connect to Telegram as it does not respond to commands. I am certain it is not the code because someone tried it ...
0
votes
1answer
69 views

Shutting down computer for night?

How can I make a script to shut down computer while I sleep? I mean, it should shut down the computer when I run the script and start the computer at 6.45 am.
2
votes
4answers
91 views

Variable in Date command

I want to use a variable inside date command . GNU date is not supportable in my system. I use Sunos and when I use date with -d option it is shwoing -d as bad substitution. #!/usr/bin/ksh ...
0
votes
4answers
56 views

print entire line after an awk and grep

I need to search multiple patterns on the third column of a file, and then print the whole line. I am using this one below but how do I get it to print the whole line where there is a match? awk '{...
0
votes
0answers
12 views

How to stop anonsurf from starting when system starts up

I am using anonsurf package to be able to visit some websites that are filtered by my ISP. My problem is that although I don't need anonsurf to be enabled for everyday use, it starts at the system ...
0
votes
0answers
24 views

Terminal Hangs when running bot

I have a bot installed on my Azure Linux VM running Ubuntu 18.04. I am running the command to start my bot, and it returns an error (see below). The console freezes as well apparently because it ...
0
votes
0answers
30 views

-bash error when trying to run bot [duplicate]

I have a bot installed on my Azure Linux VM running Ubuntu 18.04. I am running the command to start my bot, and it returns an error (see below). $ nohup python3 bot.py > nohup_bot.out -bash: ...
1
vote
2answers
41 views

How to replace multiple old file located at different location with the new files in Mac OS using script?

I've some new files in a folder A. I want to replace the old files which are located in different folders (ex. B, C, D), with the new files. Is there any way to do this in one shot by writing some ...
-1
votes
0answers
36 views

Shell script required for collection/compiling of data

I wanted to collect some stats in a specific format (of previous day) from my server log files using a cronjob everyday. Below is the sample list of log files:- -rw-rw-r-- 1 lpt tkg 2.0M **Jan 3**...
2
votes
0answers
20 views

how to output html to a file with xmllint?

How do I get xmllint to output to a file? thufir@dur:~/xmllint$ thufir@dur:~/xmllint$ xmllint --html http://www.skynet.be/nieuws-sport/weer/mijn-weer?cityId=6450 --xpath '//div[@class = "tides"]' - ...
1
vote
2answers
29 views

Calling dir names from a paramater list file

Wondering if there is a best way to call directory names and iterate as parameter from a list. Example cat /dropbox/script/DirList.txt DIR_A DIR_B DIR_C DIR_D /dropbox/dev/inbox/<DIR_A>/ *.*...
2
votes
2answers
249 views

Bash: Timer in while loop

I have a while loop in my script which waits for the connection get online and then continues. #!/bin/sh while ! ping -c1 $1 &>/dev/null do echo "Ping Fail - `date`" done echo "Host ...
1
vote
0answers
55 views

How to script AT command to modem?

Every time my USB modem (/dev/dlinkModem) gets unplugged it defaults to "radio disabled mode" (AT+CFUN:4). I can easily enough call AT+CFUN:1 through the minicom application console to enable radio ...
-1
votes
0answers
46 views

not able to create script for the below statement

I have to run in a script; I have tried, but I'm not sure how to call the shell from server. [root@server ~]# ssh storagenode storagenode:> shell Executing shell commands may invalidate your ...
-1
votes
0answers
42 views

bash shell script for following situation?

I would like to use a bash script for some .raw image merging. I have 4 .raw images in directory /home/output and the file names are 1.raw, 2.raw, 3.raw, and 4.raw. All the files (.raw) have the same ...
2
votes
1answer
51 views

Use regex for file matching, not string matching

I'm trying to figure out how to use grep to search for for a specific string, (for the sake of simplicity) say "9", and I want to search for this, again for simplicity, on all files containing the ...
3
votes
1answer
202 views

What does the slash do in 'case $1/$2' in shell script (/bin/sh)

Found this example on the arch wiki #!/bin/sh case $1/$2 in pre/*) echo "Going to $2..." ;; post/*) echo "Waking up from $2..." ;; esac and can't make out if it's a logical ...
0
votes
1answer
46 views

how to get several commands into one variable for ease of use

I am writing a script and I noticed that a certain line of code is constantly being reused. So I thought why not put it into a variable for ease of use, and when something changes, I only need to ...
0
votes
2answers
36 views

auto install minecraft script

So I was working on this script to auto install minecraft and i began to wonder is there a better way to do this? #!/bin/bash sudo apt-get upgrade sudo apt-get update sudo apt-get autoclean echo " ...
0
votes
1answer
32 views

How to count the number of arguments passed under condition?

I'm trying to create a shell script taking as argument a series of averages and assign for each note an observation, example : There are 5 averages that are introduced. There are 2 notes that are: ...
-8
votes
1answer
44 views

Write an login script on Ubuntu [closed]

The idea is that I need to write the username and the password and the script tell me who I am. if: username: admin pass: admin the script echo: "you are an admin" if: username: user pass: user the ...
1
vote
1answer
94 views

ps is not showing all processes

I used the script command immediately after I started the terminal, it started recording my current session but when i used ps command after that it is showing only two processes, one for bash and one ...
2
votes
1answer
40 views

How do I get the current focused monitor?

I'm using i3 as my WM with a Dual-Head setup. I have already mapped some keys to switch between workspaces on one of the monitors (Mod+Keypad 1..8) and I would like to use the same keybindings on both ...
0
votes
2answers
61 views

Problem with crontab

My script which starts a process and writes the PID of that process to file. This works as it's supposed to when I execute it from shell: process & echo $! > /home/xxx/PIDs/process.pid But ...
0
votes
1answer
22 views

Zsh: =() substitution with executable permission

I need to give an executable file to this command: aria2c “some-url” —on-download-complete =(echo “!#/usr/bin/env bash touch success”) Is this possible? If not, can I implement some helper ...
2
votes
1answer
102 views

Accepting CTRL-C as input

I have one problem in a Linux script. #!/bin/bash x=1; while [ $x != 0 ] do echo "Type a command:" read -r command eval "$command" if [ "$command" = end ] then x=0; fi if [ "$...
-1
votes
0answers
33 views

Script finding the total size of a directory and checking if a directory exists

I need one additional line for my script that finds the total size of a directory and shows it in bytes and another line in the beginning of this script that checks if a directory exists. That's my ...
14
votes
2answers
785 views

How does this shebang that starts with a double hyphen (--) work?

I have found the following kind of shebang in the RosettaCode page: --() { :; }; exec db2 -txf "$0" It works for Db2, and a similar thing for Postgres. However, I do not understand the whole line. ...
1
vote
1answer
48 views

bash script not working properly

I just started to learn some basic bash scripting and fail to reproduce the simples of scripts. I have got the following script: #!/bin/bash for file in "/home/test/*"; do echo test done This ...