Creating VM with Azure CLI - bash

I'm posting to see if someone can point me in the right direction. I've been trying to get this working for a few days now and I'm at a dead end.
I have tried to remove " around the variables and remove variables completely. I have tried to run this in Azure Cloud Shell, WSL, and PowerShell as a .ps1 script. However, I continue to get the same type of errors.
Here is the script.
Here is the error I am getting.
validation error: Parameter 'resource_group_name' must conform to the
following pattern: '^[-\w\._\(\)]+$'. ' not recognized. ' not found. Check the spelling and casing and
try again.
If I run a one liner with out variables I get this error.
az vm create: error: local variable 'images' referenced before
assignment
Any help would be greatly appreciated. Thank you!

So for the first error, looks like the create VM is initiating to fast to recognize the new resource group.
For the image you need to use the full URN MicrosoftWindowsServer:WindowsServer:2016-Datacenter:latest

First, it's a bash script and the variable definition is different between Windows and Linux. So I suggest you run the script in the Azure Cloud Shell with bash mode or the WSL when it's a bash script.
Second, the error shows the resource group name does not meet the Naming rules and restrictions for Azure resources, you need to read the document to check if the group name is right.

So I have found out that the issue was. It was how VS Code formats bash scripts. I'm not exactly sure how VS Code is formatting but I think it might have something to do with ASCII. I recreated the script in Azure CLI with nano and it runs fine as a bash shell script. Thanks everyone for your help.

Related

basename extra operand in GitHub actions

I have a shell script that is supposed to dynamically bundle and zip binaries based on the directory names in cmd/
When using the script locally, it works like a charm. However when the script is ran in github actions, I get the error
basename: extra operand ‘./cmd/get-reminders/’
I have a function that collects all dir names and pushes them to an array. The error above is happening when this function is ran.
prepare() {
for d in "./cmd/*/"
do
handlers+=($(basename $d))
done
}
Any ideas what the error actually is, and why github actions throws this error, and why its not happening locally?
I'm running zsh locally, github uses. bash. I don't think that's the problem, but I'm mentioning it anyway.
Thanks.
Seems like the issue was looping over a path inside quotes.
for d in "./cmd" does not work in some shell.
Correct would be for d in ./cmd

Ambiguous redirect error while using rtmpdump

So I was trying to download somevideos using rtmpdump, and I used this shell script which is supposed to download the some videos but it gave me and error message saying
./script: line 9: $1: ambiguous redirect
Now I am pretty sure that I am doing something silly so I will tell you exactly what I did. I first downloaded that above file into my system saved it as "script". And opened terminal and typed:
./script
and it gave me the above error.
Now I have also gone through this thread, and also some other threads but they don't seem help me at all and now I have nowhere to go. please save me.
script tries to use $1 as the name of a file for redirection (e.g., someCommand > "$1"), but you didn't supply a an argument when you called script.
The script needs a file as the first parameter which will have one video to download per line

AWS Data Pipeline: setting local variable in shell command

I am trying to make use of the uuid library within a shell command invoked by an AWS data pipeline. It seems like the uuid function works fine, but when I try to pass this value to a variable, the data is lost.
A snippet of my testing script below:
sudo yum -y install uuid-devel
myExportId=$(uuid)
echo 'myExportId:' $myExportId
uuid
When I look at the activity log for the pipeline I see that the uuid function seems to be working, but the variable does not seem to contain anything?
myExportId:
b6cf791a-1d5e-11e6-a581-122c089c2e25
I notice this same behavior with other local variables in my scripts. Am I expressing these incorrectly?
My pipeline parameters are working fine within the script, so no issues there.
Shortly after posting this I realized that I had encoded some of the above steps in subshells within my pipeline definition. It can be difficult debugging shell scripts embedded within JSON, so I think I will move on to using the scriptUri parameter pointing to a bash file.

how to invoke ruby script containing system command with cron job?

I have a ruby script containing system command like http://gist.github.com/235833, while I ran this script from shell, it works correctly, but when I added it to my cron job list, it doesn't work any more, the cron job is like:
10/* * * * * cd /home/hekin; /usr/bin/ruby my_script.rb
any idea what's going wrong with what i've done? Thank you.
Thank you all for your answers.
It's my mistake.
Since I'm using ssh key forwarding on the local machine, while I executed the script from the shell, the ssh key forwarding related environment variables are all sitting there, but from cron job context, those environment variables are missing.
Try to separate the things that might go wrong. The ones I can think of are:
The cron syntax - is the time value given legal and fitting your shell?
Permissions - execute permissions and read permissions for the relevant directory and file
Quoting - what scope does cron cover? Does it run only the first command?
In order to dissect this, I suggest you first run a really simple cron job, like 'ls'. Next run a single-liner script. Next embed your commands in a shell-script file. Somewhere along these lines you should find the problem.
The problem is your environment. While testing in your shell its fully equipped and boosted by your shell environment. While running under cron its very, very stripped down.
Where is the destination "." for your script? I guess it will be "/" and may not "$HOME" thus your script won't be able to write at that location and fails. Try using an absolut path for the destination.

problem with oracle sqlplus with whitespace in the path of the # command

I'm running Oracle 11g on Linux and I'm trying to run a script which will create my database. This script runs fine on windows, but when I test it on Linux, I get the following error:
SP2-0556: Invalid File Name
The problem may be that the path to the file name has a space in it. I'm going to simplify the problem down to one of the many commands I run in the file to make it simple. The sample command I'm trying to run looks like this:
sqlplus [uname]/[pw] #'../database/My Schema/create_sequence.sql'
the create_sequence.sql file has two simple create sequence commands that run fine by themselves. I strongly suspect it is due to the white space because when I change the directory name from My Schema to MySchema and alter the above sqlplus command accordingly, the script runs fine.
Like I said, this script works in windows with the spaces, but not in Linux. I suspect spaces may not be supported, but I was wondering if anyone knew any different or it there is a work-around?
side note: running a command like:
more ../database/My\ Schema/create_sequence.sql
or
more "../database/My Schema/create_sequence.sql"
prints the contents of the file to the console as you would expect. So, I think this is sqlplus (and linux) specific.
I connected to one of my Linux boxes and was pretty easily able to reproduce this issue. There doesn't seem to be any way that I can find to execute the file with the '#' option from the command line so I think you're left with the following options for work arounds:
Rename the My Schema directory to no longer have a space in it (as well as updating all other scripts that reference it
Execute the file from the directory in which it resides (I confirmed that this works, see below)
Send the file into sqlplus via stdin (see below)
You should also file a report with Oracle support as there may be a simple fix that they can provide.
Example Commands:
From Directory
cd ../database/My\ Schema
sqlplus [uname]/[pw] #create_sequence.sql
Via stdin
sqlplus [uname]/[pw] < ../database/My\ Schema/create_sequence.sql
Well, if this is a Linux issue (see my comment on your question - it works fine on Solaris), you may have to try something along the lines of:
sqlplus [uname]/[pw] < '../database/My Schema/create_sequence.sql'
You run into problems if you're trying to pass parameters to your sql script, however...
EDIT: There seems to be a Metalink issue raised for a very similar problem: "Bug 7150873 SQL scripts with filename containing spaces results in SP2-0556". It is listed as affecting 10.2.0.4 and 11.1. It is supposedly fixed in 10.2.0.5 and 11.2, neither which are available yet. It does say it's a generic issue affecting most/all platforms, so I don't know if this is your problem or not.
The specific text of the issue: "The SQLPLUS START command fails to execute SQL scripts which have a space in the filename."
Just for grins, what happens if you do the following:
sqlplus [uname]/[pw]
start '../database/My Schema/create_sequence.sql'
EDIT2: I don't know if modifying your scripts wholesale is feasible or not, but a workaround might be:
cp '../database/My Schema/file2run.sql' ./temp.sql
sqlplus [uname]/[pw] #temp.sql
rm ./temp.sql
You would need to wrap each sqlplus call this way. Another option would be to create a shell script, say with a name of mysqlplus.sh:
#!/bin/sh
cp $2 ./temp$$
sqlplus $1 #$2
rm ./temp$$
Then modify your build scripts thus:
mysqlplus.sh [uname]/[pw] '../database/My Schema/create_sequence.sql'
According to this thread on the OTN site, SP2-0556 can be caused by invalid white space characters in the file that is being executed. Likely the Linux version of SQL-Plus doesn't know how to deal with Windows newline character(s). Try deleting the existing file and recreating it with your desired commands (you said there are only 2 DDL commands so it should be easy).
If you put quotes around path, it works:
SQL > START "C:\Documents and Settings\Administrator\demobuild.sql"
This does not work:
SQL > START C:\Documents and Settings\Administrator\demobuild.sql
have you tried escaping the white space?
Try:
sqlplus [uname]/[pw] #'../database/My\ Schema/create_sequence.sql'
If you're working with this under linux you can escape the space with a '\' character like such:
sqlplus [uname]/[pw] #../database/My\ Schema/create_sequence.sql
I know it's an old question but I just ran into the same situation and after a lot of tries I made it work and I want to share my solution, it was simply put the path into quotes like this:
#"C:/Users/john/AppData/Roaming/SQL Developer/test.sql";

Resources