logo
down
shadow

Shell make system paths click-able when printed out by my shell script


Shell make system paths click-able when printed out by my shell script

By : Lukas Riepler
Date : November 22 2020, 03:03 PM
To fix this issue This is not a function of the shell, but rather the terminal (the program you use to get to the shell prompt) you are using.
You'll have to configure the terminal used and modify what it allows to be clicked/hyperlinked.
code :


Share : facebook icon twitter icon
Shell fragment to make sure only one instance a shell script runs at any given time

Shell fragment to make sure only one instance a shell script runs at any given time


By : Brian Lau
Date : March 29 2020, 07:55 AM
it should still fix some issue , Put this at the start of the script
code :
SCRIPTNAME=`basename $0`
PIDFILE=/var/run/${SCRIPTNAME}.pid


if [ -f ${PIDFILE} ]; then
   #verify if the process is actually still running under this pid
   OLDPID=`cat ${PIDFILE}`
   RESULT=`ps -ef | grep ${OLDPID} | grep ${SCRIPTNAME}`  

   if [ -n "${RESULT}" ]; then
     echo "Script already running! Exiting"
     exit 255
   fi

fi


#grab pid of this process and update the pid file with it
PID=`ps -ef | grep ${SCRIPTNAME} | head -n1 |  awk ' {print $2;} '`
echo ${PID} > ${PIDFILE}
if [ -f ${PIDFILE} ]; then
    rm ${PIDFILE}
fi
while executing a shell script in Unix Bash Shell, how is a file location resolved for relative paths?

while executing a shell script in Unix Bash Shell, how is a file location resolved for relative paths?


By : LarryMcD
Date : March 29 2020, 07:55 AM
this one helps. What do you see, if you put an ls in your script.sh? That's the starting point for evaluating relative paths. Usually it's your current working directory. So to answer your question: It's probably neither script.sh's nor file1's location.
Why probably? Because it depends on what you do in your script. If you execute an cd /home/ in script.sh, the include path changes.
Setting environment variable in shell script does not make it visible to the shell

Setting environment variable in shell script does not make it visible to the shell


By : Moh
Date : March 29 2020, 07:55 AM
hop of those help? This is how environment variables work. Every process has a copy of the environment. Any changes that the process makes to its copy propagate to the process's children. They do not, however, propagate to the process's parent.
One way to get around this is by using the source command:
code :
source ./test.sh
. ./test.sh
How to make a big shell script in a single line shell script in json document?

How to make a big shell script in a single line shell script in json document?


By : Carrie Jane
Date : March 29 2020, 07:55 AM
I think the issue was by ths following , First, consider whether you really need JSON. In your example code, you create a JSON string and then immediately decode it into a Python dict. Would it be simpler to just use a dict directly?
The problem with your current string is that you're not escaping your quotation marks properly. To avoid confusing multi-level escaping, use a triple-quoted string to represent the shell script and json.dumps to convert a dict into a JSON string:
code :
import json
jsonstr = json.dumps({"script": """\
#!/bin/bash
set -e

readonly PRIMARY=/tech01/primary
readonly SECONDARY=/tech02/secondary
readonly LOCATION=(machineA machineB)
readonly MAPPED_LOCATION=/bat/data/snapshot
HOSTNAME=$hostname

dir1=$(ssh -o "StrictHostKeyChecking no" david@${LOCATION[0]} ls -dt1 "$MAPPED_LOCATION"/[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9] | head -n1)
dir2=$(ssh -o "StrictHostKeyChecking no" david@${LOCATION[1]} ls -dt1 "$MAPPED_LOCATION"/[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9] | head -n1)

echo $dir1
echo $dir2

length1=$(ssh -o "StrictHostKeyChecking no" david@${LOCATION[0]} "ls '$dir1' | wc -l")
length2=$(ssh -o "StrictHostKeyChecking no" david@${LOCATION[1]} "ls '$dir2' | wc -l")

echo $length1
echo $length2

if [ "$dir1" = "$dir2" ] && [ "$length1" -gt 0 ] && [ "$length2" -gt 0 ]
then
    rm -rf $PRIMARY/*
    rm -rf $SECONDARY/*
    for el in $primary_partition
    do
        scp david@${LOCATION[0]}:$dir1/weekly_8880_"$el"_5.data $PRIMARY/. || scp david@${LOCATION[1]}:$dir2/weekly_8880_"$el"_5.data $PRIMARY/.
    done
fi"""})
Using two threads and system() command to run shell scripts: how to make sure that one shell script is started before an

Using two threads and system() command to run shell scripts: how to make sure that one shell script is started before an


By : user3519284
Date : March 29 2020, 07:55 AM
it fixes the issue It is not enough to "start" the first script before the second. You want the first script to actually be listening on the port you've specified. To make that happen, you need to check periodically. This will be platform dependant, but on Linux you could check /proc/PID of the first child to know what file descriptors it has open, and/or run nc -z to check if the port is listening.
A simpler approach would be to automatically retry the second script a few times if it fails to connect and the first thread is still running.
Related Posts Related Posts :
  • how to delete duplicate lines in a text file in unix bash?
  • Compare a variables in bash
  • How do I use sed on a string?
  • Using bash variables for range in sed
  • convert a DURATION HH:MM:SS to seconds in bash
  • I want to use parallel-ssh to run a bash script on multiple servers, but it simple prints the echo statements
  • AWK between 2 patterns - first occurence
  • Nginx on docker - daemonize and attach to bash
  • Delete or Replace nth line in a file after a pattern match using shell scripts
  • Actual return code for SCP
  • How to exit a bash function that expects a return
  • Bash script to split file into two files while changing output file during processing
  • Pass command line arguments via sbatch
  • variable substitution (what do you call/name this method)?
  • Call function from another shell script
  • How to Grep and Replace With Exclusions
  • shell command to remove characters after a special character in bash/shell
  • How do I run a script for 1st working day of every month in cron?
  • Bash Unexpected End of File Error After Installing RVM
  • Nested Loop with increment on inner loop?
  • video orientation detection in bash
  • Interrupt sleep in bash with a signal trap
  • Want file rename script to add number at end with fixed length
  • What's the DRYest way to replace a file with a symlink in bash
  • How to run Bitcoin's autogen.sh file?
  • Renaming files in folder and subfolders using a list- Bash Script/Unix
  • Bash command to compare more than two files
  • If It is a directory append text
  • What's wrong with my WHILE-DO loop, or why my script can't find the file I'm giving it on a plate?
  • shadow
    Privacy Policy - Terms - Contact Us © ourworld-yourmove.org