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.

Filter by
Sorted by
Tagged with
1 vote
0 answers
12 views

How to run an arbitrary command from a Kwin script?

I want to run some commands when the active window changes in KDE. How can I do this from within a kwin script? My use case is that I want to change monitor color preset for some applications, and ...
user avatar
  • 442
7 votes
1 answer
3k views

How can I shorten HH:MM:SS as much as possible?

Suppose I have the following syntax: HH:MM:SS. I want to make it as short as possible. For example, I want "00:00:30" To turn into "30". Similarly, I want "0:30:00" to ...
user avatar
  • 115
0 votes
1 answer
36 views

Remove certain words and set word at end of string in files

I have a bunch of files that contain strings similar to: Get<1>(abc) Get<2>(xyz) How can I recursively search for all files with the above pattern and remove everything before the first '(...
user avatar
  • 101
1 vote
3 answers
54 views

How to find first occurrence of string in file, set value as variable, and edit rest of file from there

I'm not sure how to title this, but here's what I've got: A file with text like: [10:03:43] 10:03:35 22JUN22 ConUP CW1B1 T CW1B3 T CW1B5 T CW1B7 T [10:03:44] ...
user avatar
  • 11
0 votes
0 answers
13 views

send multiple files as mail though mailx command

I have 3 file names present inside a .txt file I have to read all file names and send them as a attachment in a mail. Example: test.txt - (file name) -query1.dat -query2.dat -query3.dat I have to ...
user avatar
0 votes
0 answers
17 views

BASH technique to use clipboard in script? [duplicate]

My proficiency in BASH is minimal, but I did a fair bit of C back in the day. I am trying to think of a way where I can write a script which I can run, which will pass the clipboard into the script. I ...
user avatar
0 votes
0 answers
24 views

What's the recommended way to install files and modify rc files?

To help developers set up some of their environment, I have some small files that need to be installed to various locations in a user's home directory, plus modifications that need to be made to some ...
user avatar
  • 308
0 votes
2 answers
70 views

Parsing CSV with AWK, returning fields to bash var with line breaks

I have to migrate a password database (Keepass) by using a csv file of it, to a new application by using its API. The API is updated with post requests, those needs JSON data format. What I need to do ...
user avatar
-2 votes
1 answer
63 views

Using 2 For loop print the output of 2 answers from two different files

I have 2 files with some content/lines. Example : cat a.txt 1 2 3 4 cat b.txt a b c d Need to get below output using for loop 1 a 2 b 3 c 4 d I have tried the below script but ...
user avatar
  • 1,803
0 votes
0 answers
85 views

Programmatically scroll as little distance as possible in Linux

I'm working on an autoscroll script for Linux and I'm trying to find a way to scroll as little distance as possible. I know I can generate mouse events using uinput (in particular, I can send ...
user avatar
  • 1
0 votes
0 answers
21 views

Why is my udev script not working with the correct permissions?

I have the following rule: ACTION=="add", \ SUBSYSTEM=="block", \ ENV{DEVTYPE}=="partition", \ ATTRS{idVendor}=="154b", \ ATTRS{idProduct}=="00ed", \ ...
user avatar
  • 1
0 votes
1 answer
50 views

if pattern is matched then shell script

I have file that contains below words gl-events_0 gl-events_1 gl-events_2 gl-mx-events_0 gl-mx-events_1 gl-mx-events_2 so i want if match pattern in gl-events it should run command A if patter is gl-...
user avatar
  • 31
0 votes
1 answer
83 views

copying files from multiple specefic parent directories

I would like to copy files from the current directory which are divided into different subdirectories. The files I want to copy should only have True and False as their parents. True directory files ...
user avatar
0 votes
1 answer
28 views

Master script calls helper scripts which calls C program, do not know how to get return value of C program

I have a master script that calls a helper script like so: bash -ex $SOME_DIR/some_tester.sh The helper script then calls a C program like so: ./some_tester_in_C echo $? . . .other functions called ...
user avatar
1 vote
1 answer
57 views

Path in script different than actual path

When I echo $PATH in a terminal window, it outputs: /home/charles/anaconda3/bin: /home/charles/anaconda3/condabin: /usr/local/sbin:/usr/local/bin: /usr/sbin:/usr/bin:/sbin:/bin:/usr/games: /usr/local/...
user avatar
0 votes
0 answers
24 views

How do I write a script to sudo, then cd, set an environment variable and run a program?

I'm on ZorinOS 16. I recently set up SearXNG, and every time I reboot my computer I have to run a couple of commands to launch it: sudo -H -u searx -i cd /usr/local/searx/searx-src export ...
user avatar
0 votes
1 answer
70 views

Run a tmux new session with cron, then run a command

I have in my cron that auto starts a service inside a tmux if it detects that its not running. The rest of my bash script works, but if the tmux session doesn't exist, it throws an error. Which is why ...
user avatar
0 votes
0 answers
16 views

Run script to enable proxy on connecting to VPN via cisco anyconnect

I have a handy little script that toggles system-wide proxy on all programs that I use, but I only need to use it once I connect/disconnect to/from company VPN via Cisco Anyconnect. Is it possible to ...
user avatar
  • 31
1 vote
2 answers
50 views

awk script replace value with increment with if

I have a pipe delimted file d1000|1000 d1001|100 d1002|10 d1003|1 d1004| d1005| I want to modify $2 if length is less than 4 digits, and also keep empty spaces as is so trying to do it via awk script ...
user avatar
  • 1,703
0 votes
1 answer
21 views

Listing latest modified sub-directories

So I'm trying to get the sub directory that was modified last. IE. 1727 has 8 backups but I want my script I'm writing to only grep the contents of the latest backup directory. Every backup that gets ...
user avatar
  • 23
0 votes
0 answers
27 views

Rc.local in raspberry pi 3 model b

I am working on raspberry pi 3 model b arm version, running Debian I need to run a script on boot, I am doing it with /etc./Rc.local I followed this cookbook: https://www.cyberciti.biz/faq/how-to-...
user avatar
0 votes
1 answer
75 views

extract tar then enter its directory (shell scripting)

How do I make script exctract tar then enter the extracted tar directory? I was trying xtract #!/bin/bash tar -xvf $1 && cd $1 Usage example suppose there's foo.tar.xz so how to use it: ./...
user avatar
1 vote
0 answers
43 views

How to run input (x|grep y) in command [duplicate]

lets say when I execute command and then grep it for a specific output. for example: man cat|grep "Written" This gives the name of the authors. My problem is I want to do this via read. here ...
user avatar
1 vote
1 answer
39 views

how to hash a directory

looking to compare two directories to make sure they are identical, looking for a script for mac terminal that hash the directory producing a sha 256 hash value that way I can manually verify all exit ...
user avatar
0 votes
2 answers
49 views

how to compare all files inside ONE directory in bash?

example given: dir1/ file1 file2 file3 file4 how do you compare file1-file2, file1-file3, file1-file4 then file2->file3, file2->file4 and so on. In this case the name is file_number, but ...
user avatar
  • 240
-1 votes
1 answer
46 views

One master ksh file to call 2 ksh script files [duplicate]

I have 2 ksh (korn shell script) : file1.ksh and file2.ksh; and I want to have a master file ksh script that will call the 2 files; what's the code I have to put in my master file? Thanks
user avatar
  • 1
-5 votes
2 answers
34 views

Display the IP addresses of all currently configured interfaces [closed]

Display the IP addresses of all currently configured interfaces. The output should done in the following format:i The interface eth0 currently has the IP 192.168.178.22 The interface eth1 currently ...
user avatar
0 votes
1 answer
44 views

Scripting the partition shrinking

I have some disk image, taken with dd if=/dev/somedevice of=filename.img. I was able to shrink them following this tutorial. Now I would like to script all the procedure, and I managed to perform ...
user avatar
  • 111
0 votes
1 answer
22 views

How do I notify-send a long command?

I want to use notify-send to show a notification every n minutes to tell me the vpn status. The command would be running in a popup terminal I have already set up, hidden from view until I need to ...
user avatar
0 votes
1 answer
64 views

Switch case with for loop for matching string

I am trying below thing but not able to succeed I have file with below content events_0-new events_1-new events_2-new events_3-new events_4-new events_5-new events_6-new system-events_0-new system-...
user avatar
  • 31
0 votes
1 answer
14 views

Read file identify string and specific command only

I am collecting data to one file with below script while IFS= read -r line do echo "$line" echo -e "$line-new" >>newfile.txt done <"file.txt " new file has ...
user avatar
  • 31
0 votes
1 answer
60 views

Using ntfs-3g, how to parse Windows extended attributes automatically?

Using xattrs, one can access Windows extended attributes using the following command getfattr -h -n system.ntfs_ea Ntfs_Mount_Point/some_file The problem is instead of an attribute list, it returns a ...
user avatar
0 votes
1 answer
44 views

reload the i3 conf in a script

i am writing a script to quick change the mod key of i3 conf0="/home/myuser/.config/i3/config" case "${1}" in (alt) key=Mod1 ;; (win) key=Mod4 ;; (*) printf "Invalid ...
user avatar
0 votes
1 answer
41 views

bashscript for quick change i3 mod key

i am trying to write a bash script to quick change the $mod key of i3 i moved the "set $mod Mod4" to the end of my conf #!/bin/bash $1=key $alt="alt" $win="win" sed '$d'...
user avatar
0 votes
3 answers
37 views

If the value in the first column is the same, compare second column and if the second one is different save the value in the first column in txt file

I try to write script to get the the values from the first column, which are the same, but have a different value in the second column. Does someone know how to do it ? Example: I have this .txt file: ...
user avatar
0 votes
2 answers
65 views

Understanding functions (Bash)

I see the below function used in a bash script: LOG_FILE="/root/collect.log";\ date_info() { local cmd; cmd=$(basename $0) echo "$(date --rfc-3339=seconds) $cmd.info: $*&...
user avatar
  • 1
0 votes
1 answer
33 views

Script for copy bookmarks from one pdf to another

I want to transfer bookmarks from a series of uncompressed pdf files to their compressed copies (these copies do not have the original bookmarks). I know how to do this one by one using pdftk. First I ...
user avatar
  • 218
0 votes
1 answer
40 views

In a Bash script, not able to use while and for loop together. Getting unexpected end of file error

#!/bin/bash while read -r col1 col2 col3 col4 col5 col6 col7 col8 col9 for i in 8.00 7.50 7.00 6.50 6.00 5.50 5.00 ; do echo '6.0' $i $col6 >> 1.dat done < "sih1.66" getting error ...
user avatar
0 votes
1 answer
51 views

Can I change system files from custom kickstart .iso?

I have set up a Kickstart .iso installation of CentOS 7 and it installs nicely (.iso is compiled with ks.cfg file inside). What I haven't figured out yet is if I could edit system files from within ...
user avatar
1 vote
1 answer
58 views

How to add DNS server via script?

How to add DNS server via script if nameserver is not written in resolv.conf . like first check following lines are there or not in resolv.conf file: nameserver 8.8.8.8 nameserver 8.8.4.4 If not then ...
user avatar
  • 11
0 votes
1 answer
32 views

Purge old folders without find

Here I am trying to delete old folders which are older then xdays. Path of these disk are mentioned in file_path.txt What I need here is to search each path available in the mentioned file & ...
user avatar
  • 2,953
1 vote
2 answers
106 views

Change color of a certain lines from an output bash

I have this output from a drive diag command. Slot Number : 0 Drive's position : DiskGroup 0 Media Error : 0 Other Error : 0 Predictive Failure : 0 Raw Size ...
user avatar
2 votes
5 answers
382 views

echoing value in same indexes of 2 arrays simulataneously

I have 2 arrays to prcoess in bash script simultaneously. First array contains sort of lables. Second array contains values, as under LABELS=(label1 label2 label3 labe4 ) VALUES=(91 18 7 4) What's ...
user avatar
  • 1,703
0 votes
0 answers
31 views

How to replace text in file - conditions and arithmetic required

I need a script to change content in some text files. This a bit beyond my limited bash skills. Maybe perl or python would be a better approach, I have no experience with either of these. I have a ...
user avatar
2 votes
2 answers
80 views

Move arbitrary string to end of command

I often find that I've concocted some incantation which I'd like to reuse, but it's far too susceptible to ad-hoc tweaking to store as a function. These commands often have some critical variable ...
user avatar
  • 14.4k
0 votes
1 answer
65 views

Can't make awk loop over file values

Hi guys I'm trying to loop over the values of a file (or multiple files) passed as a parameter to the script as in, ./myscript file1 file2 ... but awk only recognizes the first line of each file. #!/...
user avatar
0 votes
0 answers
34 views

Insert a new host into dhcpd.conf

This is my first post on this forum. I need a little advice on how I add an entry host to our dhcpd.conf file. I have +50 servers, that I need to add this fixed MAC-address into to and it's a hassle ...
user avatar
  • 1
0 votes
2 answers
73 views

Adding a floating point number to the looping index in bash script

I am trying to add a floating point number to the looping points. My loop is non sequential. j=9.46 for i in 8.0 7.5 7.0 6.5 ;do $i = $i + $j |bc echo '$i' i also tried ans=$(( x + y )) k=$[...
user avatar
-1 votes
1 answer
38 views

How to execute other scripts such as bash and jython, from a bash script?

I have a script called test.sh which is located in the directory /home/user with the following code: #!/bin/bash echo "Execute command number 1 (bash)" . /opt/IBM/taddm/dist/bin/control.sh ...
user avatar
0 votes
1 answer
52 views

xfconf-query: create property for a plugin: Property X does not exist on channel Y

I'm trying to configure the XFCE clock plugin to use a custom format but getting Property "/plugins/plugin-12/digital-format" does not exist on channel "xfce4-panel". $ xfconf-...
user avatar

1
2 3 4 5
85