Azure Bash - Permission denied when running . <(sudo wget -q -O - https://aka.ms/microservices-data-aspnet-core-setup) - bash

I'm trying to setup my environment to learn azure from the Microsoft learning page https://learn.microsoft.com/en-us/learn/modules/microservices-data-aspnet-core/environment-setup
but when i run . <(sudo wget -q -O - https://aka.ms/microservices-data-aspnet-core-setup) to pull the repo and run the services, i get the error below
~/clouddrive/aspnet-learn/modules/microservices-data-aspnet-core/setup ~/clouddrive/aspnet-learn
~/clouddrive/aspnet-learn
bash: /home/username/clouddrive/aspnet-learn/src/deploy/k8s/quickstart.sh: Permission denied
bash: /home/username/clouddrive/aspnet-learn/src/deploy/k8s/create-acr.sh: Permission denied
cat: /home/username/clouddrive/aspnet-learn/deployment-urls.txt: No such file or directory
this used to work until it stopped working and I'm not sure what caused it to break or how to fix it.
I've tried deleting the 'Storage account' and the resources, but doesn't seem to work. also, when i delete the storage account and create a new one then try again, it seems to have the old data stored and i need to run a remove, so somehow this data isnt really being deleted when i delete the 'Storage account'
Before running this script, please remove or rename the existing /home/username/clouddrive/aspnet-learn/ directory as follows:
Remove: rm -r /home/username/clouddrive/aspnet-learn/
any idea what is wrong here, or how i can actually reset this to work like a new storage?
Note: I saw some solutions which say to start with sudo, for elevated permission, but didnt manage to get this to work

I have done the repro by following the given document
Able to deploy a modified version of the eShopOnContainers reference app
Again I executed the same command ,
. <(wget -q -O - https://aka.ms/microservices-data-aspnet-core-setup)
got the same error which you have got
If we try to run the deploy script without cleaning the already created resource/app,will get the above error.
If you want to re-run the setup script, run the below command first to clean the resource
cd ~ && \
rm -rf ~/clouddrive/aspnet-learn && \
az group delete --name eshop-learn-rg --yes
OR
Remove: rm -r /home/username/clouddrive/aspnet-learn/
Rename: mv /home/username/clouddrive/aspnet-learn/ ~/clouddrive/new-name-here/
The above command removes or renames the existing /home/username/clouddrive/aspnet-learn/ directory
Now you can run the script again

Related

Commands without sudo in bash do not work

I am running a bash script and these commands in the script will not work without sudo in front of them. The script.sh is located in a folder such as /jobs/script.sh
Example of commands I am trying to run in the script.sh -
mv /var/app/myapp /var/app/myapp.old
rm file.tar.gz
tar -xzf /home/ubuntu/file.tar.gz -C /var/app/
All the above work if I add sudo in front of them.
I am trying to figure out what permissions are required for them to work without adding sudo in the script.
I have tried giving the script.sh rwx permissions and changing owner to root.
I'm learning permissions in linux, so I'm new to this. Basically what permission should the script.sh have so that I dont have to use sudo in the bash file? Any insight would greatly help.
When you run sudo <some command>, then <some command> is run by the root user (Super user do). The reason you might need to run any command using sudo is because the permissions on the files that command reads/writes/executes are such that only the "Super user" (root) has that permission.
When executing the command mv fileA fileB, the executing user would need:
Write permission to fileB if fileB already existed
Write permission to the directory containing fileB
From what you said it’s most likely you want read and write permissions you can achieve this with chmod
Chmod +[permission] filename
(+ is used to add permission you can also use - instead to remove it)
Where permissions can be:
r —> read
w—> write
x —>excecute
... and more
FOR EXAMPLE: it seems you write permissions for the first file so :
chmod +w /var/app/myapp
Will fix problem

WGET seems not to work with user data on AWS EC2 launch

I launch an centos AMI I created, and try to add user data as a file which looks like this:
#!/bin/bash
mkdir /home/centos/testing
cd testing
wget https://validlink
So simply, on launch, the user data creates a folder called testing and downloads this validURL which I will not put as it links to my data - however it is valid and accessible.
When I launch the instance, the folder testing is created successfully, however there is no file inside the directory.
When I ssh into the instance, and run the wget command as a sudo, the file is downloaded successfully inside the testing folder.
Why does the file not get downloaded on the ec2 launch through user data?
You have no way of knowing the current working directory when you execute the cd command. So specify full path:
cd /home/centos/testing
Try this:
#!/bin/bash
mkdir /home/centos/testing
cd /home/centos/testing
wget https://validlink
Run it using the root user.
Try this instead:
#!/bin/bash
sudo su
yum -y install wget
mkdir /home/centos/testing
cd /home/centos/testing
wget https://validlink

Bash CLI: Is there a way to simultaneously create and set permissions on a file without repeating the filename?

Is there a way to simultaneously create and set permissions on a file without repeating the file name?
I tried:
touch text.txt && chmod u+x text.txt
This gives me permission denied when I run it and I want to know how to fix it and: How do I get rid of the repetition?
If you are getting a permissions error when you run your command, that suggests that you do not have permissions to create files where you're trying to create the file. Regarding the rest of your question:
As BroLow said, you can use umask to affect the default permissions of files created in your session. However, this can be inconvenient, particularly if you only want the new permissions in effect for a single command.
You can use the install command to create and set permissions on a file:
install -m <mode> -o <owner> -g <group> <srcfile> <destination>
If you want to create an empty file, you can use /dev/null as a source:
install -m 644 /dev/null <destination>

Why does the lftp mirror command chmod files

I'm very new to lftp, so forgive my ignorance.
I just ran a dry run of my lftp script, which consists basically of a line like this:
mirror -Rv -x regexp --only-existing --only-newer --dry-run /local/root/dir /remote/dir
When it prints what it's going to do, it wants to chmod a bunch of files - files which I grabbed from svn, never modified, and which should be identical to the ones on the server.
My local machine is Ubuntu, and the remote is a Windows server. I have a few questions:
Why is it trying to do that? Does it try to match file permissions from the local with the remote?
What will happen when it tries to chmod the files? As I understand it, Windows doesn't support chmod - will it just fail gracefully and leave the files alone?
Many thanks!
Use the -p option and it shouldn't try to change permissions. I've never sent to a windows host, but you are correct in that it shouldn't do anything to the permission levels on the windows box.
I think that you should try
lftp -e "mirror -R $localPath $remotePath; chmod -R 777 $remotePath; bye" -u $username,$password $host

Tomcat startup script permission on Mac OS X

I'm struggling with a Mac OS X 10.5.8 that I've started using recently for development. I successfully installed tomcat and create launchd.conf for my environment variables.
I believe it works fine. Coz I can build a project with Netbeans using maven and cargo plugins successfully so i found online a script for start and stop the tomcat
#!/bin/bash
case $1 in
start)
sh /Library/apache-tomcat-6.0.20/bin/startup.sh
;;
stop)
sh /Library/apache-tomcat-6.0.20/bin/shutdown.sh
;;
restart)
sh /Library/apache-tomcat-6.0.20/bin/shutdown.sh
sh /Library/apache-tomcat-6.0.20/bin/startup.sh
;;
*)
echo "Usage :start|stop|restart"
;;
esac
exit 0
That script was created in nano in sudo sh
but when i want to run it. is spit out this
sh: /usr/bin/tomcat: Permission denied
I've added chmod 755 *.sh and *.bat inside /Library/apache-tomcat-6.0.20/bin
Still access denied so what do I go around that? I have the admin privileges on the machine.
Thanks for reading
Go to Tomcat bin directory and run the below command:
chmod +x *.sh
This worked for me.
Where did you install the tomcat script to? I'd recommend you install it to /usr/bin. Once installed, make sure the permissions are correct (i.e. chmod 755 /usr/bin/tomcat). You can then confirm with ls -l /usr/bin/tomcat.
If you still get errors once the permissions on /usr/bin/tomcat are correct, then you can add the following two lines following the #!/bin/bash line.
set -x
set -v
With the above lines, bash will output additional information that will allow you to tell what's being executed and where the error is happening.
1) Go to the tomcat directory, which preferably should be "/usr/local/folder-name"
2) Check for the permissions for the folder: ls -l
3) Change the permissions using: sudo chmod -R 755 folder-name
4) Change the owner to the current owner: sudo chown -R owner-name:group-name folder-name
e.g sudo chown -R userName:admin folder-name
Try executing the script again and it should work.

Resources