I have a random folders names structure directories as below: Each file.txt has one value e.g. -300. I am trying to loop through those folders with the random naming and collect the data in one text file in the Main directory maintaining the original directory name as below: The result.txt should contain as b…
Tag: bash
bash check if the outputs (.txts) in multiple directories contained certain string
I generated multiple script.txt in multiple directories for different subjects. Now I need to check if all the script.txts contain string ” finished without error”. If yes, returned ok; if no, returned parents directory, so that I knew which subject went wrong. It was fine when I checked in subdir…
Bash export variables but only for current command
I want to load some environment variables from a file before running a node script, so that the script has access to them. However, I don’t want the environment variables to be set in my shell after the script is done executing. I can load the environment variables like this: However, after the command …
How to print IP address from Shell Script?
Below is my command line I want to get output of IP address(10.1.2.133) alone as output. How to write command line for that? Answer If you don’t mind a solution which is not elegant, but does the job, just pipe the output of your grep command into This splits the line first by the = and then :. If the
Linux Command Line – list all directories containing .js files, and copy the directories and their contents to a new folder
Here is the code I already have that finds and lists all directories containing .js files (excluding the node_modules directory). As you can see, listing those directories is no problem. However, rather than list the directories, I would like to copy them (and their contents) to a new folder, preferably all i…
How to run a file in variable
I want to run this command: ././pscan `cat ips` 22 but the script don’t run corectly and i want to run command e.g: ././pscan 1.1 22 ././pscan 2.2 22 ././pscan 3.3 22 ././pscan 4.4 22 ././pscan 5.5 22 the script pscan works perfectly when i type on single command ././pscan 1.1 22 and i want to run more …
If statements accepting yes or no in bash script?
I am trying to accept user input of yes or no to a question and depending on the answer read back the value of my variable. I can never get commands attached to variables to work or my if statements to accept yes or no. It just keeps going to “not a valid answer”. Please let me know how to
How I can count how many suspended proceses there are in a shell script linux bash
I tried to write a shell script that shows and counts how many suspended processes there are. But I succeeded only to show the suspended processes with: I tried to count the suspended processes with: Of course this didn’t work because it counted every word there was even with the first row that had the …
Why docker exec command ingore bashrc inside docker container?
So. I have docker image with ubuntu (also creared container from this image). On my docker container I see this output: On my container on file ~/.bashrc (it is /root/.bashrc) I’m export some variables: When I try to execute command on docker container using “docker exec” I don’t see m…
Read last line of file after the file was modified
I have a problem with reading the last line of file in Linux Ubuntu. I have a file named auth.log and I’m trying to read it last line after new line was added (after file was modified). I know i need to use tail -1 /var/log/auth.log to get last line but I don’t know how to check the file every