1

I have worked my best on trying to make a script to iterate through 2 arrays. The values in each array needs to get its value input into a string called ExecuteSyncoid based on a string called SyncoidCommand so a command with the changed parts will be executed.


The String is called

SyncoidCommand

The command/string from SyncoidCommand that needs to be changed looks like this

SynCoid-IterateThroughDataSets.sh -s /home/darkyere/Scripts/Syncoid/shortsourcelist -d /home/darkyere/Scripts/Syncoid/shortdestinationlist -c "syncoid <username>@XXX.XXX.XXX.XXX:SourceDataSet DestDataSet --compress none --sshcipher [email protected] --sshport <Port> --sshkey "/Dest/To/KeyFile" --no-privilege-elevation" -p <Password>

Now the two parts that needs to be changed is in

<username>@XXX.XXX.XXX.XXX:SourceDataSet DestDataSet

Where SourceDataSet and DestDataSet is the two in question.

It will in the long run allso need to work in the Opposite way looking like this

SourceDataSet <username>@XXX.XXX.XXX.XXX:DestDataSet

I have tried these different ways And few more i didnt keep in my attempts

The

$SourcePath

# And

$DestPath

Is the value from the two arrays i am attempting to insert into "ExecuteSyncoid"

ExecuteSyncoid="${SyncoidCommand/SourceDataSet/$SourcePath}"  
ExecuteSyncoid="${SyncoidCommand/DestDataSet/$DestPath}"

# ----------


ExecuteSyncoid=$(echo $SyncoidCommand | sed "s+SourceDataSet+$SourcePath+g")
ExecuteSyncoid=$(echo $SyncoidCommand | sed "s+DestDataSet+$DestPath/+g")

But the changed string allways resembles something like

syncoid <username>@XXX.XXX.XXX.XXX:SourceDataSet Storage/WallaBag --compress none --sshcipher [email protected] --sshport <Port> --sshkey "/Dest/To/KeyFile" --no-privilege-elevation" -p <Password>

So the code changes DestDataset without a problem.

But in all my attempts including more than i posted it never changes the

<username>@XXX.XXX.XXX.XXX:SourceDataSet

To etc.

<username>@XXX.XXX.XXX.XXX:Storage/WallaBag

Is there anyone out there with some bash knowledge that can help me change the part of the string with ":" in it No matter if it is

<username>@XXX.XXX.XXX.XXX:SourceDataSet DestDataSet

# Or

SourceDataSet <username>@XXX.XXX.XXX.XXX:DestDataSet

Best Regards, And thank you for reading Darkyere

3
  • As far as I can see, you correctly set ExecuteSyncoid, but then overwrite it with the other change. You need to apply both changes to the same input like ExecuteSyncoid=$(echo $SyncoidCommand | sed "s+SourceDataSet+$SourcePath+g;s+DestDataSet+$DestPath/+g") Commented May 6, 2022 at 8:19
  • I might not have explained it well enough. The origional command is stored in the variable SyncoidCommand and then transferred on each change to the variable ExecuteSyncoid. So the origional SyncoidCommand never changes, only ExecuteSyncoid. So that part should be fine. Commented May 6, 2022 at 10:58
  • 1
    Aaah i see it now. I had to think about what it meant first. I actually overwrite ExecuteSyncoid 2 times removing the first change i made. Just by making ExecuteSyncoid= and the second as ExecuteSyncoid2 the second variable have both changes. Thank you a lot. this helped me getting past this point. Commented May 6, 2022 at 14:28

1 Answer 1

1

(Answer moved from edit of the question to a community wiki answer.)

This was the error

ExecuteSyncoid="${SyncoidCommand/SourceDataSet/$SourcePath}"  
ExecuteSyncoid="${SyncoidCommand/DestDataSet/$DestPath}"

This was the fix thanks to Philippos

ExecuteSyncoid="${SyncoidCommand/SourceDataSet/$SourcePath}"  
ExecuteSyncoid2="${SyncoidCommand/DestDataSet/$DestPath}"

It was as simple as me overwriting the first string with the second. After changing the second sting it worked.

Thank you and have a good day.

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.