Scheduled Maintenance: We are aware of an issue with Google, AOL, and Yahoo services as email providers which are blocking new registrations. We are trying to fix the issue and we have several internal and external support tickets in process to resolve the issue. Please see: viewtopic.php?t=158230

 

 

 

Help with executing scripts

New to Debian (Or Linux in general)? Ask your questions here!
Post Reply
Message
Author
Level1Coder
Posts: 4
Joined: 2009-12-19 09:14

Help with executing scripts

#1 Post by Level1Coder »

Hi all,

New Debian user here (moved from Ubuntu). I'm still farily new to Linux and need help understanding how scripts work.

I have a fairly fresh install of Debian 5 and trying to run a script:

script filename: mysql-cron-backup-script
--BOF--
#!/bin/sh
/usr/bin/mysqldump -uUSERNAME -pPASSWORD my_db_name > my_db_name.sql
--EOF--

When I type in "mysql-cron-backup-script" in the command line, it returns:

-bash: mysql-cron-backup-script: command not found

Is there something I'm doing wrong or didn't install?

User avatar
obeliks
Posts: 14
Joined: 2009-02-14 19:51
Location: Finland

Re: Help with executing scripts

#2 Post by obeliks »

First make sure that the script is executable:

Code: Select all

chmod 744 mysql-cron-backup-script
Secondly make sure that you either give direct path to the script or if you are in the same directory where the script is, put

Code: Select all

./
in front of it.
Image

Level1Coder
Posts: 4
Joined: 2009-12-19 09:14

Re: Help with executing scripts

#3 Post by Level1Coder »

It's working now, thanks for the tip!

rweaver
Posts: 67
Joined: 2008-12-04 21:44
Location: Independence, Ohio

Re: Help with executing scripts

#4 Post by rweaver »

You have your raw password for mysql in that script, you should not be using 744 permissions. 700 would be more appropriate.
Pantek, Inc. - http://www.pantek.com/ - info@pantek.com
+1-877-LINUX-FIX - Expert Open Source Technical Support

User avatar
cnoyes
Posts: 114
Joined: 2009-12-06 18:13
Location: North Carolina
Contact:

Re: Help with executing scripts

#5 Post by cnoyes »

rweaver wrote:You have your raw password for mysql in that script, you should not be using 744 permissions. 700 would be more appropriate.
+1, you should always use the least possible permissions in any situation. For a good primer on what linux permissions are, and how they work try http://www.tuxfiles.org/linuxhelp/filepermissions.html
=================
chris@suxbox.org
Debian Sid
=================

User avatar
obeliks
Posts: 14
Joined: 2009-02-14 19:51
Location: Finland

Re: Help with executing scripts

#6 Post by obeliks »

Good points rweaver and cnoyes! I didn't take those things into account carefully enough in this case. In general, it's a good thing however to show the script to others to let them learn if one like to do so.
Image

User avatar
cnoyes
Posts: 114
Joined: 2009-12-06 18:13
Location: North Carolina
Contact:

Re: Help with executing scripts

#7 Post by cnoyes »

obeliks wrote:Good points rweaver and cnoyes! I didn't take those things into account carefully enough in this case. In general, it's a good thing however to show the script to others to let them learn if one like to do so.
His point wasn't that you posted your script here, it was that you have your raw password in that script, and don't have it locked down on your system.
=================
chris@suxbox.org
Debian Sid
=================

User avatar
dbbolton
Posts: 2129
Joined: 2007-06-20 08:17
Location: Iapetus

Re: Help with executing scripts

#8 Post by dbbolton »

If you use a lot of custom scripts, it is a good idea to add the directory containing those scripts to your $PATH environment variable.

For example, I keep my scripts in $HOME/bin. To add that directory to my $PATH, I put the following line in my shell's rc file:

Code: Select all

PATH=$HOME/bin:"${PATH}"
export PATH
GitHub | zsh docs in Letter PDF
Telemachus wrote:Put down the CGI.

User avatar
obeliks
Posts: 14
Joined: 2009-02-14 19:51
Location: Finland

Re: Help with executing scripts

#9 Post by obeliks »

cnoyes wrote:
obeliks wrote:Good points rweaver and cnoyes! I didn't take those things into account carefully enough in this case. In general, it's a good thing however to show the script to others to let them learn if one like to do so.
His point wasn't that you posted your script here, it was that you have your raw password in that script, and don't have it locked down on your system.
Ouch, misunderstanding. My native language is not English, maybe it was because of that. I'll try it again.

What I meant was that in general it's a good thing to show a script to other users who use your linux system (not here at the forum) and let them to view the script in case they want to learn something about it. Of course if the script contains personal or system critical data, permissions should be set accordingly. I'm sorry about the confusion.
Image

rweaver
Posts: 67
Joined: 2008-12-04 21:44
Location: Independence, Ohio

Re: Help with executing scripts

#10 Post by rweaver »

Pretty much any script with a password in it should NOT be system viewable by anyone but you.

Another simple solution would be to source a ~/.mysql_backup file which had the variables set then reference them as variables in the script, that way the 744 permission wouldn't be a danger.

Of course on the otherside of that everytime it runs your password is viewable to everyone on the system who does a ps auxw
Pantek, Inc. - http://www.pantek.com/ - info@pantek.com
+1-877-LINUX-FIX - Expert Open Source Technical Support

User avatar
AdrianTM
Posts: 2499
Joined: 2004-09-19 01:08

Re: Help with executing scripts

#11 Post by AdrianTM »

One idea is to put the password in a script that's locked down from reading from other users and read that script from the general script that is available to other people to read (if that's what you want). This way you can keep one script viewable and editable by normal user and have the password in a file that can be edited only by root and read only by the user you want.

By the way "./" is simply a shortcut to "current folder" you should be able to run the script by specifying the full path, like /home/username/scriptname, you can't execute it just by typing "scriptname" because that folder is not in the PATH variable.
Ubuntu hate is a mental derangement.

Post Reply