Linux Noob Questions...

bob4432

Lifer
Sep 6, 2003
11,726
45
91
i have done quite a bit of linux reading lately but need some advice from the peeps who are more familiar with this os.

i have installed bf:v server and a server management script. when i installed bf:v i had to become root. now whenever bf:v makes a log file, it is owned by root and if i want to transfer / view this log file i have to become root and type this command: chmod -R 777 /bfv dir. my question is is there any way to make me the owner of the program instead of root or is there any way i could run that command every 6 hours or so? this way my stats program could get the log files via ftp and i wouldn't have to be bothered with it?

the other question is how do i start something on machine startup. i need to start up the server version of the program i use for remote admin of the bf:v server on startup of the machine. currently i just go to the dir the file is in and type in the command to run it, but i would like for this to start automatically, again so it will be as automated as possible. with this file i do not need to be root, just my regular login name.

thank you in advance for you time and assistance :)
 

drag

Elite Member
Jul 4, 2002
8,708
0
0
Well to scedual commands you generally use 1 of three ways.

Way #1 is to scedual a command to start up as soon as another command finishes.

If you were to type:

ls ; echo "finished"

the ls command would run and then after that is finished then echo would print out "finished".

You can use that in scripts to do stuff. The ; would mean the same as if you started a command on the next line in a script, it just makes it easier to type it all out on one line.

Way #2 is to use batch scedualling. To do this you use the at command.

Basicly you can type:
at 22:00 # then it will give you a carrot prompt
> This is your command line
> This is another command that will run after that command.
> then another command
> (hit ctl-d to exit)

So then whatever commands you type will now run at 22:00 hours, which is 10 pm.

Way #3 is to use crontab command. Your OS has a basic crontab configuration in /etc/crontab. Each user has their own crontab entry that you can access by typing "crontab -e". It will open up in your text editor (which is configurable btw so if you don't like the default editor you can change it).

The system crontab entry goes like this:

minute hour dayOfTheMonth Month DayOftheWeek user command

so a entry would be:

30 20 ^ ^ ^ ^ drag echo cool

so that would run the command "echo cool" as the user drag ever day at 8:30pm.

You can use ranges and steps for the feilds. So if you put 1-20/3 in the hour feild then that would run a command every 3 hours from 1am to 8pm (I am sure that you understand that everyhting is according to a 24 hour clock)

A entry of */6 for the hour feild will run the command every 6 hours all day long.

Each user has there own crontab and it only differs from the system's crontab in that you can't get to it from normal
/etc/crontab file, only crontab -e command and there is no "user" feild since you can only execute commands as that user.


So with "at" you can secudaul 1 time commands at any time. It can take days and months and years entries, too.

With crontab you specify commands you want to run over and over again. Set and forget.


Also a thing about the "man" command. Some words/commands have more then one man file. To search for man files go:
man -k keyword.

So crontab has multiple man files.
So go:
man crontab
man -S 5 crontab

the -S modifier specifies the library to use. You generally have one file for the actual command, one file for hte configuration, one file for developers and programmers. Some commands have many files, some only have one.

See "man man" for the manual for man. ;)

see here for more detailed look at unix job scedualling

Also for the log file. The simpliest solution would be just to edit the scripts and put a "chown" command at the end changing the owner of the file to your user.
chown user:group file

But if you want to run commands as a different user you use the sudo command. Normally it just means that you run the command as a root from a normal user, but it goes both ways. Like this:

sudo -u username whoami

And that will execute the command as that user.

Hope all that makes sense.

edit:

PS. becarefull with PATHS when your run commands. Crontab (or is it "at"?) uses different enviromental variables then you normally use. So you may have to specify the full path to commands like /usr/bin/perl, instead of just "perl". So be sure to test out your setups with simple commands and sample scripts before you set everything in motion. Just to make sure that their is no user error.

Once you get it going, then it will require no manual intervention unless you want to change something.

To find commands you type "which command" and that will give you the path to the command. To find your current path type "pwd". To find your enviromental variable for your executable search path you go "echo $PATH".

Check out the guides section at www.tldp.org for linux basics, linux administration, bash basics, and advanced bash scripting guides among others. It also has extensive howtos for different specific subjects.

The command line is very powerfull, and scripting makes it doubly so. If you want you could figure out how to do stuff like setup a script to check on your game service, and if the game deamon crashed it would make sure and kill the proccess and then start up the service again so that you don't have to be their to restart BF:V everytime it screws up, if it screws up. Things like that.
 

Nothinman

Elite Member
Sep 14, 2001
30,672
0
0
my question is is there any way to make me the owner of the program instead of root or is there any way i could run that command every 6 hours or so? this way my stats program could get the log files via ftp and i wouldn't have to be bothered with it?

Unless it needs to do something really strange there's no reason you should need to run the program as root. As long as you have rights to it (read and execute, generally) you can run it as any user. The running user will need to have write rights to the log dir, but that's about it.

the other question is how do i start something on machine startup. i need to start up the server version of the program i use for remote admin of the bf:v server on startup of the machine. currently i just go to the dir the file is in and type in the command to run it, but i would like for this to start automatically, again so it will be as automated as possible. with this file i do not need to be root, just my regular login name.

There are multiple ways to do this that depend on the distro used. If it's RedHat based you can put any commands you want in /etc/rc.local and they'll be executed at the very end of the boot sequence, so to run the server as your user you could put 'su - <username> -c /path/to/server --and-its-switches'. If you omit the 'su - <username> -c' part it'll run as root.

Or you can write a small startup script and put it in /etc/init.d like the other services on the machine. On Debian there's an example script in /etc/init.d/skeleton, but I don't think other distros ship one.