I'm working on a script which handles disaster recovery for a system I'm developing. Part of the script will also be used for initial setup. It needs to require as little user interaction as possible. It also needs to be run as root during most of the process. The problem is that there comes a point where some of the software can't be compiled or installed as root. So root needs to su to a regular user who then has to sudo in order to compile & install the aforementioned software. After all this, the script needs to revert to it's original state, running as root. I've never encountered a situation where root had to su to a normal user in order to sudo as root.
I'm creating a bash script to do some tasks for me. I would like the script to be run at a set time of everyday. My first question is if it is possible that if one of the commands in the script requires sudo, is there a way to get around it with out making sudo not require a password. Such as, is there a way to include the password in the script? If that is the case, I can always just set the file as read only by sudo. I've been looking for a way to do this, with no success. if I have a command that wants input, how do I give it to the program. For example, if I want to make a zip file that is encrypted, the command would go as:
Code:
zip -r example * -e
now how would I get the script to insert my wanted password.
Just installed 10.04 64bit and in gnome-terminal i have no bash completion when sudo is used.For example:apt- gives apt-getbut sudo apt- does nothing, i get no suggestions from the terminal.
I have written a tiny script which switches between 2 CPU frequency throttling governors. Now I need to assign it to a shorcut key though "Preferences->Keyboard Shortcuts".
Here is the script:
Code:
#!/bin/bash if [ `cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor` = 'ondemand' ] then
[code]....
As you can see this script involves sudo. I know that usually running commands with sudo requires "Run in Terminal" option for a shortcut, but in "Keyboard Shortcuts->Add" there is no option to run command in terminal. When I double click on the script and choose "Run in Terminal", then it functions as it should. How can I make this script execute by doing "Run" and not "Run in Termnal"?
If I call a bash script with sudo, for example: sudo bash script.sh Do I still have to use sudo inside the script in cases like this: sudo apt-get update
I had some bash scripts on Ubuntu 09.10 (mint version) that fail to work on Ubuntu 10.04. The line that fails is the following:
Code: # cat file_with_my-password.txt > sudo -S something cat: invalid option -- 'S' Try `cat --help' for more information. In my case "something" mounts some filesystems (that fail to load from fstab - bios "fake" raid 10), but I get the same error for any sudo command. It is the same script that used to work under 09.04 :-/
I just set up apache on my PC and I cant change the permissions by right clicking because "I'm not the owner" and instead of using the chmod command on every file that I would like to edit I would just like to write a script on a text file, save it to my desktop so all I have to do is double click on it and boom I can edit all my files, etc.
I would like to know how do I print the line # in a script. My requirement is, I have a script which is about ~5000 lines long. If there are any errors happen I just exit. And I would like to add the line # of the script where the error happened.
Code: #!/bin/bash trap "echo 'you got me'" SIGINT SIGTERM # to trap ctrl+c echo "Press ctrl+c during 5 sec loop" for ((i=0;i<5;i++)); do
[Code]...
How come code behaves normally and stops when ctrl+c signal is caught and resumes, but after I use at least one timeout read in the code it looks like, if signal is caught again it doesn't pause the execution but skips the loop. If you remove -t (timeout) option from the read, both loops look the same!
Now in my bash script, I want to get the output /home/user instead of $HOME once read. So far, I have managed to get the $HOME variable but I can't get it to echo the variable. All I get is the output $HOME.
I have written quite a few separate bash & scripts and php scripts that up to now I have run from cron jobs. However I have to estimate how long each takes to run, before running the next and so it probably takes much longer than necessary to run them all. They have to run in order.
Now there are so many I am thinking it would be better to have a master bash script that would run one after the other, but I am not sure how to get the master script to wait before starting to run the next script. Is this possible and is there a command that will make the script wait between bash and php scripts , for them to finish, before running the next?
I think it would be better to count the len and remove 3 chars to right to get the extension, but it can be macintosh filenames with have 4 chars for extensions.
I need to rename the resulted searched files from a loopI have the following code:
find . -name DOC* | while read i do find $i -type f -name '*.txt' done
basically, I am searching for all txt files inside any folder starting with DOC name.this code is working fine with me.I need to rename those .txt files to .txtOLDOS: Ubuntu 10.4Bash shell
How can I give www-data permission to use sudo? I used to assign permission to users to use sudo using KDE but don't know how to do it on a headless server.Basicly I have a web application running that wants to call a command that needs root privs. When it calls this command it's running as www-data. I guess it's not working as www-data is not allowed to use sudo. If it can use sudo I could for example...Code:echo "password" | sudo -S "some admin command here"I could be wrong but i'm petty sure I just need to give www-data permission to use sudo?
I wrote a shell script and was able to compile it using SHC. after that i copied it to the /bin folder and tried running it as a normal user, but i keep getting the error " operation not permitted killed "
I tried changing the permissions. but it doesn't work. it only works with sudo. there must be another way. otherwise it won't be linux right?
I was trying to list sudo users in a Linux Machine,
[root@redhat ~]# grep -v -E '^#' /etc/sudoers root ALL=(ALL) ALL %work ALL=(ALL) ALL %dilipvp ALL=(ALL) ALL
where work is a group and dilipvp is user. Can you help me in creating a better script which can list the members of the group work as well. and why I am getting empty space in between.
How to use sudo to run a perl script with the environment variable JAVA_HOME on linux? Running testenv.pl as sudo do not pickup the environment variable JAVA_HOME value. code...
I am trying to write a bash script that sources another bash script. Essentially, I need a few lines to check to see if a certain variable is set. If not, I set it manually, and then source a scripts with that variable in the path. I wrote a test script to try it, but for some reason the last line does not work. Here is what I wrote:
#!/bin/sh source ~setupdir/setup.shrc #just a test, this line works echo ${#SETUP} # prints 0 if setup is not set, which it isn't if [ ${#SETUP} -eq 0 ] then SETUP="~setupdir" fi echo $SETUP # prints ~setupdir
I have written a script to run commands on remote servers, it is working fine. But when I am running "sudo commands" on the remote servers, it asks for me password after prompting for ssh password. I am unable to automate this password prompt (which is just after ssh password prompt). This is the function I am using to provide passwords
Code:
pass () { cd $DIR/"$dt1"_"$dt" /usr/bin/perl << 'EOF' use strict;
[code]....
I want the same function to be used , when it expects for sudo passwords for any of the below lines:
Code:
[sudo] password for vikas: orPassword: This is my "cmd" file passed in pass () function.
i'm in the process of learing C++. currently i'm creating shell scripts to get things done. i'm just curious how, as a programmer using C++ you would get a similar job done.as an example i have a script that takes the contents of files, pipes it to some sed and awk commands, which is piped to create a new file. that file is then imported into a mysql database.if you were going to do this in C++, would you call the sed/awk programs to modify the file, or can it be done within the program itself? i'm probably jumping the gun here because i've just started learing about pointers so this is above my ability
explain the difference between these two commands. I'm currently reading about changing your mac address and both of these commands show up a lot. They sound like the same thing to me. Is one better than the other, or do you need to use both to change your mac address?
Code: sudo ifconfig eth0 down sudo /etc/init.d/networking stop
I have a problem when I want to use su I get this error:Code:su: pam_start: error 26I have googled it so I found this topic (http://www.linuxquestions.org/questi...r-26-a-615024/) but it didn't really help me. There was a reply on that topic and his question was what the output of this was:
A day ago I finally got around to upgrading the PackageKit installation that had been sitting for a week and a half, so I found a new upgrade for sudo available - the one that gives the sudoreplay command, I forget which version number it is exactly. When I try to use the sudo command I get this notice in my terminal:Code:Can't open /var/db/sudo/me/1: Permission deniedI didn't get it before. What do I have to do to make it open? I'm using SELinux in enforcing mode if that helps.
I have read a lot of questions from people wanting to take Debian (or some other distribution) and make its sudo command act more like the way Ubuntu's sudo does. I want to do the exact opposite, I want to make Ubuntu's sudo command act more like the sudo command from another distribution. ie I want there to be one root password
Creating script that converts hex to dec. But without using bc calculator or other methods that could convert it in one line. I need to make something like this script that converts dec to hex.
I have a basic awk script that can read a file named 'server_info' and output to the screen which fax lines are not working. Now I want to make the script execute commands instead of printing to the screen but I am having trouble... This is better explained by my code below:
test.sh Code: #!/usr/bin/awk -f # #The name of this script is test.sh