bash – List path of same folder content of two hard drives

I have two hard drives that I want to use for backing up copies of Instructional DVDs. The probleme is that in Drive A the DVD might be in homeinstructionalsGman but in Drive B it might be in homeDVDs. Ideally, I’d want to see which folders are similar (So I know that DVD X is backed up in both drives) and also another list of which folders are different.

bash – Shell Script para mostrar listado por terminal linux

necesito mediante un fichero que me han proporcionado llamado “grupos.txt” mostrar por terminal lo siguiente:

En el fichero proporcionado tenemos 4 grupos:
administradores: 4 usuarios
dam: 10 usuarios
daw: 7 usuarios
asir: 7 usuarios

El fichero grupos.txt contiene la siguiente información:
introducir la descripción de la imagen aquí

Hasta el momento lo más cerca que estoy de mostrar es esto:

introducir la descripción de la imagen aquí

bash – How to open another Account’s User folder using Terminal?

I used to be able to use one of these commands to switch to another user account (my own) to work on it.

john$ login admin
password:

admin$ open .
LSOpenURLsWithRole() failed with error -610 for the file /Users/admin/.

I have tried other methods as well.

john$ su - admin
john$ exec su - admin
john$ sudo -u admin bash

They all result in the same error. I understand it’s a security restriction. The question is what rules are restricting this? I do have the password shouldn’t I be allowed, once signing in, access to those files?

What can I do to gain access as if I am in that user account?


EDIT

Also tried:

john$ ssh admin@localhost
Password:
admin$ open .
LSOpenURLsWithRole() failed with error -610 for the file /Users/admin.

bash – Piping nc to sed and evaluate datetime for each row

Could someone provide any idea, how could i pipe data from nc to sed (or awk, or anything) and evaluate and write to file a timestamp after each row?
What i have:

# cat /etc/systemd/system/ncserver.service
(Unit)
Description=netcat listener
After=network.target

(Service)
Restart=always
RestartSec=1
ExecStart=/usr/bin/bash -c '/usr/bin/nc -n -v -l -k -p 1313 >> /opt/data/$(hostname)-$(date -u +%%y%%m%%d-%%H).txt'

(Install)
WantedBy=multi-user.target

simple listener – receives text via raw tcp, sends into the file (restarts by cron once a day to generate new file)

I want to append current timestamp to each row of text coming (at the beginning or the end of the row, doesnt matter).
Tried sed, awk, but the problem is that i cannot evaluate date for each row – it evaluates only once, when service started.
Looks like this

109582 ?        Ss     0:00 /usr/bin/bash -c /usr/bin/nc -n -v -l -k -p 1313 | /usr/bin/sed 's/^/'$(date +%s)
 109583 ?        S      0:00 /usr/bin/nc -n -v -l -k -p 1313
 109584 ?        S      0:00 /usr/bin/sed s/^/1617555467;/g

Pipe may be not the answer at all, but i’m kinda limited by bash.
Any ideas?..

bash – How to Automatically Run a Batch File on a Self-Cleaning Virtual Machine?

I am trying to learn a little bit of test automation. I know some batch files, I am brushing up my “PowerShell” skills and – who knows – I might even end up using some bash, in the long run.

I have this self-cleaning virtual machine that gets completely wiped-out after an user log-out. Upon the next user log-in, the Registry and the start-up folders get cleared. All I can do is to manually double-click on desktop icons in order to start some static software applications that I am recurrently using.

The batch file part I have managed to do by myself. I am enabling the execution of local “PowerShell” scripts and then running a script that is changing some desktop icons. Here is how the Change_Desktop_Icons.BAT batch file is looking right now:

@Rem  Just add a "Rem" command in front of the next line for debugging purposes.
@Echo Off

Rem Setting the local variables up.
Set PowerShellBase="%SystemRoot%System32WindowsPowerShellv1.0"
Set PowerShellExecutable="%PowerShellBase%PowerShell.Exe"
Set PowerShellScript="Y:DigitizationPowershellThe_My_Computer_Desktop_IconChange_Desktop_Icons.PS1"

Rem Changing the current directory to the local base installation of PowerShell.
ChDir %PowerShellBase%

Rem Enabling the execution of local scripts on this machine.
%PowerShellExecutable% -Command "& {Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser}"

Rem Executing the script that changes some desktop icons.
%PowerShellExecutable% %PowerShellScript%

@Rem  Just remove the "Rem" command in front of the next line for debugging purposes.
Rem Pause

The “PowerShell” part has nicely been debugged by some great people who are roaming about on this website and for whose help I am thanking them again. Great lessons I am learning here every day.

Now, the problem is that I always have to manually double-click on the Change_Desktop_Icons desktop icon. After the manual double-click and the execution of the scripts, the desktop icons get nicely changed, as it can be seen in the picture that appears below.

What I am now looking for is to somehow automate even the manual double-click. I am aware that the “Task Scheduler” static software application might be used in this respect, but I do not fully know how.

The virtual machine is quite tightly set up. I am not allowed to use certain static software applications such as, for instance, the “Group Policy“.

At this point, I have posted this question on the “Stack Overflow” website. Apparently, due to the fact that it is less related to the Software Development process and more suited for the general Personal Computer usage, the question has been closed.

I am pasting here the two comments that I have received on this question.

  • Add a scheduled task to run the Powershell script on logoff. There’s plenty of articles around that demonstrate how to do this – Scepticalist yesterday

  • I agree with @Scepticalist. Also, isn’t there a public folder on your V.M.? You can also toss it in there and have it run at log-in/start-up – Abraham Zinala yesterday

These are the two comments that I have appended to the question in order to reply to the commenters:

  • Unfortunately, it seems that I am not allowed to create a scheduled task on this virtual machine, @Scepticalist. Its user name is EE65037. I am checking its user name and it is perfect. I am copy-pasting its password, so I know for sure that it is all right. The only remaining cause for the happening of this weird behavior might be the fact that the system administrative team could have enforced a while ago some kind of group policies that are currently disabling the creation of scheduled tasks by the users of these virtual machines. – Mihai Dobrescu 22 hours ago

  • Indeed, @Abraham Zinala, there are a few directories that I am still allowed to use and that are intact after the logoff/logon process couple. The desktop folder is \ISXPFV01.hd00.unicreditgroup.euus_qv2_dem_user_data_pool_nra$EE65037.HD00Desktop . I am also attempting to maintain the shell-scripts in the Y:DigitizationGitHubShell-Scripting folder. I do not know how to place a scheduled task in either of these directories, but – first of all – apparently I am not allowed to create any kind of scheduled tasks, at all, on this virtual machine. – Mihai Dobrescu 22 hours ago

After my latest two comments, to my surprise, I have managed to create the scheduled task somehow. I cannot explain why this time it did not ask me for my credentials. It simply created it and saved it.

I have tested it and it was nicely running the Change_Desktop_Icons.BAT batch file. The problem is that the same thing did not happen at the user logon, when I want it to be run.

Is there a way to save the scheduled task in the Y:DigitizationGitHubShell-Scripting folder, for example? Or is there another way to solve this problem?

bash – Function for commiting – what do you think?

For easier work with Jira, I have prepared the following function to commiting:

commit() {
  BRANCH=$(git branch --show-current)
  REPOSITORY=$(git rev-parse --show-toplevel)
  IFS='-' read -r -A BRANCH_PARTS <<<"$BRANCH"
  NUM_REGEX='^(0-9)+$'
  JIRA_ID_DEFINITION="${REPOSITORY}/.jira"
  PROJECT_PREFIX=$(cat $JIRA_ID_DEFINITION)

  if (( ${BRANCH_PARTS(1)} == 'dev' )) && (( ${PROJECT_PREFIX} != "" )); then
    # If branch has a format: dev-{projectId}-{taskId}
    if ( "${#BRANCH_PARTS(@)}" -ge 3 ) && ! (( ${BRANCH_PARTS(2)} =~ $NUM_REGEX )) && (( ${BRANCH_PARTS(3)} =~ $NUM_REGEX )); then
    
      COMMIT_MSG="${BRANCH_PARTS(2):u}-$(printf %03d ${BRANCH_PARTS(3)})"
    
    # If branch has a format: dev-{taskId}
    elif (( ${BRANCH_PARTS(2)} =~ $NUM_REGEX )); then
      COMMIT_MSG=$PROJECT_PREFIX

      for part in "${BRANCH_PARTS(@)}"; do
        if (( ${part} =~ $NUM_REGEX )); then
          COMMIT_MSG+="-$(printf %03d $part)"
        fi
      done
    fi

    COMMIT_MSG+=": $1"

  else
    COMMIT_MSG=$1
  fi

  if ask "(VRS-Env) Skip CI process?" N; then
    COMMIT_MSG+=" (skip-ci)"
  fi

  echo -e "n::> $COMMIT_MSG"
  if ask "Is that correct?" Y; then
    git commit -m "$COMMIT_MSG"
  fi
}

The idea is simple:
If current the root of project (root of Git) contains the file .jira, we are getting it’s content (it contains only Jira’s ID, i.e. PROJ).
Next, we are checking if branch’s name starts with dev – if not, the commit name will be “clean” (without prefix) but if branch is i.e. dev-13 so the commit will be prefixed by PROJ-13: (rest of commit message).
But, we can have a branches for another projects, i.e. dev-proj2-22 so we will handle it too into format PROJ2-22: (rest of commit message).

It’s working like I want but I think there is some code which can looks better.
What do you think? What can I do better?

bash – Merging contents of multiple files into single .csv file

I have multiple .txt files in a directory in my Ubuntu system and i need to prepare a csv report by appending the contents of each txt file into single csv file.

File Name-1: 123_rajaram.mk

open group MG_ATT_MEMB * //...
write group MG_ATT_MEMB * //PROJECT/...
write group MG_ATT_MEMB * //PROJECT_MANKIND/...
read group MG_ATT_MEMB * //NETWORK/...
write group MG_ATT_MEMB * //CONTENTS/...
write group MG_ATT_MEMB * //FILE/...
open group U8_USER * //SOURCE/Auto/Admin/...

File Name-2: 123_ramesh

open group MG_ATT_MEMB * //...
write group MG_ATT_MEMB * //PROJECT/...
write group MG_ATT_MEMB * //TEST-KERNAL/...
read group MG_ATT_MEMB * //MRJWL/...

But I am not sure from where to start. Any help would be appreciated.

bash – Is it possible to pre install some files when I create a bunch of users?

I know a template file like the following can create a bunch of users they doesn’t exist yet.

ubuntu01:passwd:2000:10000:,,,:/home/ubuntu02:/bin/bash
ubuntu02...
ubuntu03...
...

To copy a few files to each of them, I guess I can run command like

cp /path/to/file /home/ubuntu01
cp /path/to/file /home/ubuntu02
cp /path/to/file /home/ubuntu03
...

Is it possible to do the job when I create the users?

Bash array with dynamic name

I made the following code :

tableList=("books" "centres" "contacts" "courses")
for tbName in ${tableList(@)}; do
        declare -a tableName${i}="ar_${tbName}"
        for col in $(mysql --login-path=local $db -Bse "SELECT COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_SCHEMA = 'GED' AND TABLE_NAME = '$tbName'"); do
                eval tableName+=("$col")
        done
done
set

The purpose was to get columns name for each table described in array tableList and put them in an array for each table with ar_+table name as array name.

for instance all columns name for tables books should should have been put in an array called
ar_books.

like this :

ar_books = ("book1" "book2" "book3)

Unfortunately this does not work, and the set show that the new array name (ar_courses for instance) is put in an array called tableName as first occurence but no array called ar_courses had been created.

I looked over stackexchange since yesterday afternoon and I don’t see how to make this works.

Any help would be appreciated.