Server Basics

HHunt,

Thanks for the info! So basically, just write the program in the text editor, then open the compiler and tell it the file to compile and off you go..yes?

I have done a little reading on python and most people recommend it as one of the beginner languages...they say it is very straightfoward and easy to follow. I think I will give it a try just for kicks..after all, if I am gonna have a server, you gotta start somewhere! Does linux have a command prompt of sorts like windows?
 
That's the basics, yes.
Write, compile, run, debug, repeat until tired or out of caffeinated drinks.

As for shell, definitely. Most linux servers run without a GUI.
The most common is bash, which is a world in itself. It is programmable, so a lot of simpler things will be written as shell scripts. Because of it's programming constructs, it's also much more powerful than the windows shell.

I personally prefer tcsh to bash, and all the same things can be said for it. I'd recommend bash, though. It's by far the most common shell, so most things will assume that's what you use. Even in tcsh-friendly environments like FreeBSD, most scripts are for sh (bash is a superset of sh).
 
Check out eclipse for an environment.

Emacs is another popular choice but you do the integratiion yourself.

Note that gcc does not install by default on all distributions. On Debian derivates like Ubuntu you have to add the development packages yourself.
 
Thanks again ya'll! I really appreciate all of the help although I fear I am sinking deeper and deeper into linux with no sign of return to anything conventional...but I like it!! :D
 
Mahachippy said:
Thanks again ya'll! I really appreciate all of the help although I fear I am sinking deeper and deeper into linux with no sign of return to anything conventional...but I like it!! :D

I personally use kate (a KDE text editor with an integrated shell window and syntax highlighting) for most things, definitely a matter of taste.

And yeah, it moves from a tool to a hobby rather fast. :D
(Or a lifestyle, if you aren't careful. ;) )
 
I'll look into kate..I was exploring the terminal window...is that the same as the shell? When I typed help, it gave me a few things, then said to type info bash to learn more about it. So, what all can I do with bash..bash is the command editor..yes?
 
Oh yeah, I also meant to ask..if that is so with bash and the terminal window, do any of you have a link to a sample simple bash shell that I could run to see it work? (Maybe something like the first program in a c or c++ class...you know the one where you write a few program lines to say hello world or something along those lines)
 
Mahachippy said:
I'll look into kate..I was exploring the terminal window...is that the same as the shell? When I typed help, it gave me a few things, then said to type info bash to learn more about it. So, what all can I do with bash..bash is the command editor..yes?

You'll get a shell in a terminal window, yes.
The shell is the program that takes your commands and does something with it. It's like a mutation between command.com and a simple script interpreter.
(For a full-screen shell you can press Ctrl+Alt+Fn, where n is 1 to 6.
While there, Alt+Fn will switch between terminals. Alt+F7 should return you to X.)

Most things are explained in manpages, so "man bash" should also be informative.
You can search manpages with apropos. "apropos bash" will return all manpages with "bash" in the short description. "man man" is also worth skimming.

As for what you can do with bash, give me a moment.

edit: This should work.
Code:
#!/bin/bash
text="Hello, world"
for i in $(seq 5)
do
echo "$text $i"
done
Put this into a text file and save it somewhere. A filetype of .sh is customary, but not neccesary.
In a shell, move into the right directory [1], mark the file as executable ("chmod +x filename"), and try to run it by typing "./filename".

What it does:
The first line says "start '/bin/bash' and feed it the rest of this file". You can do the same thing with any other interpreter, too.
The next one puts "Hello, world" into a local variable.
The $()-construction means "run the command inside, and use the text it printed".
"seq 10" prints the numbers from 1 to 10.
For-loops with a list of items (space-separated) will run as many times as there's items in the list, so this one goes 10 times. (In this particular one, i will have values from 1 to 10.)
An odd thing with bash scripts is that when you put values into variables, you just use the name. When you want to use their value, on the other hand, you put a $ in front of the name. ("echo i" will print "i", but "echo $i" will print whatever value i contains.)

As for things to do in the shell, I'm fond of the tab completion. Type part of a file name, press tab, and it'll finish as much of it as possible. [2]
Press tab twice, and it'll show you all the files which match what you've written so far. [3]

[1] cd basically works as you'd expect it to. "cd ~" will move to your home folder, as will "cd /home/yourUsername".
"cd .." moves up a folder.
"cd /" takes you to the bottommost folder of the file system tree.
"pwd" (Print Working Directory) tells you where you are.
[2] If you've got two files, "abcd1234" and "abab1234", and you type "a<Tab>", it'll go to "ab". Type "c<Tab>", and it'll finish the rest.
[3] In the above example, you could press Tab twice when it stopped at "ab", and it would show you both files.
 
ahh...okay...thanks..I never realized so much information was built into the program. I mean I knew there were help files and such, but those information commands are really helpful as I am starting to grasp linux.
 
Oh indeed. There's an immense amount of built-in documentation, and people still think it's sparsely documented compared to the BSDs. :)

I found one of my screenshots of kate, btw. It's in windows, but it actually runs on another FreeBSD box. [1] Should give you an idea.

[1] X is a fascinating system.
The communication between the things that want to be displayed (clients) and the program that displays them (the X server) is normally through unix sockets, but it's very possible to use TCP instead, and route it over a network.
On that screenshot, kate runs on another computer, but talks with an X server in windows that actually displays it and returns keypresses and mouse events. It's suprisingly simple to set up, too.
 
Yeah, I know and I am really glad becuase I like knowing what is going on behind the scenes. I mean not to bash windows...I still use it and like it, but I just feel like linux will let me see and do more on the the code level. Anywho, thanks again to all for the help so far...I know I will have a lot more questions as I dig deeper...I just hope ya'll don't get sick of me around here! :)
 
Mahachippy said:
Yeah, I know and I am really glad becuase I like knowing what is going on behind the scenes. I mean not to bash windows...I still use it and like it, but I just feel like linux will let me see and do more on the the code level. Anywho, thanks again to all for the help so far...I know I will have a lot more questions as I dig deeper...I just hope ya'll don't get sick of me around here! :)

Oh, no problem. I wonder if this shouldn't be moved to the linux/BSD-forum, though. :)
 
HHunt said:
Oh indeed. There's an immense amount of built-in documentation, and people still think it's sparsely documented compared to the BSDs. :)

I found one of my screenshots of kate, btw. It's in windows, but it actually runs on another FreeBSD box. Should give you an idea.

HHunt,
Thanks for the screen shot! That look at lot like the limited coding I did in c and c++. I mean I guess there should be similarities, but from what I had heard in the past, I guess I though that linux used some kind of discreet hard to understand language. But now I see it is not and yet I have another reason to get sucked into the linux world! :D


[1] X is a fascinating system.
The communication between the things that want to be displayed (clients) and the program that displays them (the X server) is normally through unix sockets, but it's very possible to use TCP instead, and route it over a network.
On that screenshot, kate runs on another computer, but talks with an X server in windows that actually displays it and returns keypresses and mouse events. It's suprisingly simple to set up, too.

That is great! So, windows and linux play well together? How about windows, linux, and mac? When I setup my server, I will have my windows box, my mom's mac and linux on my server.
 
HHunt said:
Oh, no problem. I wonder if this shouldn't be moved to the linux/BSD-forum, though. :)


Yeah I had that thought once I started asking so much about linux. So, moderator if you feel the need to please move this to the linux forum.
 
Well, linux drivers and kernel code is mystical and/or strange, and GUI programming will use some more or less sane toolkit.
GTK is usually done in C, while QT is C++. (Nominally, at least. QT provides a lot of things for you, so it's almost like a language in itself.)

The basics, however, are quite simple. If you want to use system libraries, they're rather well documented in chapters 2 and 3 of the manpages. Some of the things might take a bit getting used to, but it's not that bad if you've done C before.
(A lot of things want a pointer to a structure as an argument and puts their results there,for instance.)
 
HHunt said:
You'll get a shell in a terminal window, yes.
The shell is the program that takes your commands and does something with it. It's like a mutation between command.com and a simple script interpreter.
(For a full-screen shell you can press Ctrl+Alt+Fn, where n is 1 to 6.
While there, Alt+Fn will switch between terminals. Alt+F7 should return you to X.)

Most things are explained in manpages, so "man bash" should also be informative.
You can search manpages with apropos. "apropos bash" will return all manpages with "bash" in the short description. "man man" is also worth skimming.

As for what you can do with bash, give me a moment.

edit: This should work.
Code:
#!/bin/bash
text="Hello, world"
for i in $(seq 5)
do
echo "$text $i"
done
Put this into a text file and save it somewhere. A filetype of .sh is customary, but not neccesary.
In a shell, move into the right directory [1], mark the file as executable ("chmod +x filename"), and try to run it by typing "./filename".

What it does:
The first line says "start '/bin/bash' and feed it the rest of this file". You can do the same thing with any other interpreter, too.
The next one puts "Hello, world" into a local variable.
The $()-construction means "run the command inside, and use the text it printed".
"seq 10" prints the numbers from 1 to 10.
For-loops with a list of items (space-separated) will run as many times as there's items in the list, so this one goes 10 times. (In this particular one, i will have values from 1 to 10.)
An odd thing with bash scripts is that when you put values into variables, you just use the name. When you want to use their value, on the other hand, you put a $ in front of the name. ("echo i" will print "i", but "echo $i" will print whatever value i contains.)

As for things to do in the shell, I'm fond of the tab completion. Type part of a file name, press tab, and it'll finish as much of it as possible. [2]
Press tab twice, and it'll show you all the files which match what you've written so far. [3]

[1] cd basically works as you'd expect it to. "cd ~" will move to your home folder, as will "cd /home/yourUsername".
"cd .." moves up a folder.
"cd /" takes you to the bottommost folder of the file system tree.
"pwd" (Print Working Directory) tells you where you are.
[2] If you've got two files, "abcd1234" and "abab1234", and you type "a<Tab>", it'll go to "ab". Type "c<Tab>", and it'll finish the rest.
[3] In the above example, you could press Tab twice when it stopped at "ab", and it would show you both files.


Now that was just cool!! Sure it is a simple program, but I feel like a million bucks right now! Also, thanks for the explanation on the steps...that really helped me understand what was going on! I really like this...I am definitely going to get into working with shells and such!

Well, linux drivers and kernel code is mystical and/or strange, and GUI programming will use some more or less sane toolkit.
GTK is usually done in C, while QT is C++. (Nominally, at least. QT provides a lot of things for you, so it's almost like a language in itself.)

The basics, however, are quite simple. If you want to use system libraries, they're rather well documented in chapters 2 and 3 of the manpages. Some of the things might take a bit getting used to, but it's not that bad if you've done C before.
(A lot of things want a pointer to a structure as an argument and puts their results there,for instance.)

Okay. I mean a few things are a little different, but the code you showed me was a little similar, but the concepts and ideas seem to be the same overall.
 
Mahachippy said:
HHunt,
That is great! So, windows and linux play well together? How about windows, linux, and mac? When I setup my server, I will have my windows box, my mom's mac and linux on my server.

They play rather well with the right tools.
I use cygwin in windows to get an X server, and putty as my SSH client. Then it's a case of firing up a cygwin window (and getting a bash shell), and starting the X server with something like "X -ac -multiwindow&". [1]
That done, I use putty to connect to the other computer, and check "enable X forwarding" in the "SSH->Tunnels"-panel. Every X-program I start in that ssh session will pop up in windows.

Reminds me: SSH is fantastic. You'll always want sshd running on your servers.
Basically, it's like encrypted telnet plus support for sending all sorts of other data through the same connection. You can get to a shell on them from anywhere with a network connection, and that will let you do almost everything. You can upload files safely to it with scp. You can set up tunnels for all sorts of network traffic. And specifically, it can set up things so X-programs will be forwarded correctly for you with a simple switch or toggle. [2]

As for integration, you'll want to set up samba sometime. It's basically windows file and printer sharing reimplemented for linux. (Minus the GUI, plus some reliability and speed.)
There's a whole lot of other ways to connect things. I'm personally fond of the way KDE 3.4 handles samba. (It's like the "network neighbourhood"-browser in windows, but a bit less prone to freezing.)
You can also mount a windows share to a directory on the linux box to use it seamlessly there. (Sort of like mounting it to a drive letter in windows.)

OS X comes with big parts of the FreeBSD userland, so many things are directly translatable from linux (or even better, FreeBSD). You've got bash as the default shell in recent versions, tcsh in the first ones. There's probably an ssh client, and I even think there's a server in there. It supports windows file sharing, so if you get samba up, it should work here, too.

[1] "-ac" means "let everyone connect". This is a security risk if outsiders can get to the computer, but some firewalling should fix that. It shouldn't be neccesary, but the alternatives have a tendency to crash the X server. It's not the most stable software I've used.
The "&" means "start this, but in the background". Without it you can't use the shell until the program exits.
[2] If you're sitting in X on one linux box, you canopen a terminal, do "ssh -X user@otherComputer". You'll get a shell on the other computer. Start any X program, and it appears locally.
 
Mahachippy said:
Now that was just cool!! Sure it is a simple program, but I feel like a million bucks right now! Also, thanks for the explanation on the steps...that really helped me understand what was going on! I really like this...I am definitely going to get into working with shells and such!

Okay. I mean a few things are a little different, but the code you showed me was a little similar, but the concepts and ideas seem to be the same overall.

Glad you liked it. It took a touch of translation after writing it in FreeBSD. :)
(Bash is an addon here, so it lives in /usr/local/bin/ , and we use jot instead of seq.)

As for C, that was demo code more than anything, but even the more involved things aren't really too hard to follow.
Edit: The only code I have lying around here is some school work. It's a fairly small client/server affair, well documented. Shame every comment and variable name is in norwegian. :p
 
HHunt,
Thanks again for all of your explanations! Also, thanks for all of the progam tips...I will look into those for my server once I set it up. I can't wait to start programming in linux...once I get a second hdd..I am going to put a full install of linux on it and do a dual boot or something so that I can practice coding in linux.

Edit: The only code I have lying around here is some school work. It's a fairly small client/server affair, well documented. Shame every comment and variable name is in norwegian.

I don't speak norwegian, but the ironic thing is that I am part norwegian...my grandmother's mother immigrated to the U.S. in the 1800's! Btw...I dunno what your job is, but you are one heck of a teacher! :D
 
Mahachippy said:
HHunt,
Thanks again for all of your explanations! Also, thanks for all of the progam tips...I will look into those for my server once I set it up. I can't wait to start programming in linux...once I get a second hdd..I am going to put a full install of linux on it and do a dual boot or something so that I can practice coding in linux.


I don't speak norwegian, but the ironic thing is that I am part norwegian...my grandmother's mother immigrated to the U.S. in the 1800's! Btw...I dunno what your job is, but you are one heck of a teacher! :D


Sounds good. It's a fun environment.
As an example of something a bit more typical (and very excessively commented), I put together a small thing here. It might be easier to read without the comments, so I also stripped it.
To compile it, use "gcc tid.c -o time", and it'll make an executable called "time". Run it with "./time".
(If the compile fails, you're missing some basic development tools and/or libraries.)
Note that e.g. "man localtime" should give you a manpage for the C function.

And speaking of ironic, two of my great-grandmothers (diferent sides) were american. ;)
Also, thanks a lot. Not suprisingly, both my parents (and several others in my family) are teachers. It's either inheritable or contagious. :)

I'm a mere unemployed CompSci-student, and this is more or less exactly one of my subjects from last year. ("Linux systems administration and programming") Got an A, probably because I ended up helping half my class through it. (Forced me to repeat the basics a lot of times, and find good ways to explain it. You're the lucky guy who get's the refined, final versions. :D )
 
Quick question...how do I use gcc tid.c -o time do I type it in the terminal window? If not, how do I get to the gcc compiler? From there I know what to do...I just don't know where the gcc compiler is.

That is ironic about your great-grandmothers! I was wondering if you were a teacher or had teaching in your blood, becuase you know how to really explain things well..which I really, really apprecite!

I am a soon to be computer science student...will be the spring of '06...right now I am working at a local department store to save up some money for tuition, so I am doing this stuff as both a hobby for a server in the future and also for practice...I want to go into my computer science program with at least a little bit of knowledge of what I am doing!

Oh yeah and thanks for the final version...it is very, very nice!! :D
 
Mahachippy said:
Quick question...how do I use gcc tid.c -o time do I type it in the terminal window? If not, how do I get to the gcc compiler? From there I know what to do...I just don't know where the gcc compiler is.

That is ironic about your great-grandmothers! I was wondering if you were a teacher or had teaching in your blood, becuase you know how to really explain things well..which I really, really apprecite!

I am a soon to be computer science student...will be the spring of '06...right now I am working at a local department store to save up some money for tuition, so I am doing this stuff as both a hobby for a server in the future and also for practice...I want to go into my computer science program with at least a little bit of knowledge of what I am doing!

Oh yeah and thanks for the final version...it is very, very nice!! :D

Yeah, just type it in a terminal (in the directory where tid.c is stored).
It doesn't really matter where it is as long as the directory is in your path, and I can practically guarantee that it is. (If you have gcc at all, that is.)
If you want to know where something you can run is, you can use "which", e.g. "which bash". (It should say "/bin/bash".) [1]

To see your current path, try "set | grep PATH". The line that starts with "PATH=" lists the directories that are searched.
Another thing with bash (and all the linux shells) is piping: "|" means "send the output of the command to the left into the command on the right". "set" shows all the environment variables that are set for you. That list is sent to "grep", a command that searches for text. It takes the output of "set" and filters away the lines that don't contain "PATH".

I'm quite happy with a few things about norway, specifically the almost-free schools and dirt-cheap national student loans. (I'll have to pay them down some time, but at least I can pretend that I'll get a well-paid IT job to help me with that.) After all, there's got to be some benefits to living in a wealthy social-democratic welfare state ;)

Good luck, btw. You should do fine if you keep up this level of interest. :)

And thanks again. I kind of enjoy explaining things, as you've probably noticed. :D
(I guess I should consider applying as a teaching assistant.)


[1] As for why it's called "which", I guess it's because it's useful to decide which copy is used if there's several executables with the same names in the different directories in your path. (It will use the first one it finds when searching your path from the left side.)
 
I searched my path and did some sniffing, but didn't find tid.c and when I typed in your program, I get some errors. However, I don't think that is your fault...I have a feeling that I might not have the gcc complier becuase I am running a live cd version of linux. However, once I get a full verison, I will look for it again. But, this in no way is going to stop me from playing around...I am certainly hooked and want to learn more! Oh and thank you so much again for explaining the path commands and such to me...that was very helpful and you make things very easy to grasp. That concept seems a little foreign to me because when I took my c programming class, our only resource was the textbook. I am not saying the textbook was bad or anything, they just didn't give as clear examples or explanations. Anywho if you do decide to become a teaching assistant, I envy those students!

My grandparents have been to Norway a few times...they don't go anymore due to age, but they were there during the '96 olympics and had a great time...brought back some nice goodies for my sister and I as well!!


I am going to try my hardest to keep up my enthusiasm because I really like this linux stuff!!

And thanks again so much for the help!
 
Mahachippy said:
I searched my path and did some sniffing, but didn't find tid.c and when I typed in your program, I get some errors. However, I don't think that is your fault...I have a feeling that I might not have the gcc complier becuase I am running a live cd version of linux. However, once I get a full verison, I will look for it again. But, this in no way is going to stop me from playing around...I am certainly hooked and want to learn more! Oh and thank you so much again for explaining the path commands and such to me...that was very helpful and you make things very easy to grasp. That concept seems a little foreign to me because when I took my c programming class, our only resource was the textbook. I am not saying the textbook was bad or anything, they just didn't give as clear examples or explanations. Anywho if you do decide to become a teaching assistant, I envy those students!

My grandparents have been to Norway a few times...they don't go anymore due to age, but they were there during the '96 olympics and had a great time...brought back some nice goodies for my sister and I as well!!


I am going to try my hardest to keep up my enthusiasm because I really like this linux stuff!!

And thanks again so much for the help!

Well, you'll have to download tid.c, since it's the file I linked to. :)
GCC might very well be missing from a LiveCD. If they have to remove something, it's not the most useful thing to keep.

And again, thank you.
What makes this fun it the way you're reacting much like me, on a shorter timescale. :D

'94, not '96, BTW. I was there as a 10-year old, very memorable. Lillehammer is still very marked by it. :)
(I've got some family up there, and did a month as an army recruit just outside the town.)

Edit: 03:34 here. I'll be heading for bed.
 
Rats! '94...sorry 'bout that...little rusty since I discovered computers a few years ago!! Anywho, yeah, I have heard and see pictures from my grandparents about the beauty of Norway....would love to see some of the landscape..fjords and such. Also, the roadway troll houses intrigue me! :D Btw..another interesting thing...we are the same age...looking at your sig. your birthday is only 4 days after mine...mine is Nov. 1st...great month btw! :)

I'll look for tid.c

Thanks for everything...have good night! Oh yeah..sent you a pm.
 
I'm in the southeastern part of the country, so it's mostly farmlands, forests and cities. Very undramatic. (Kind of nice, though.)

And I'd completely forgotten that I put in my birthday. :D
Yeah, good month, in a way that's completely unrelated to the metorological conditions.
(It's said that norwegians always fall back on the weather for the lack of a better subject, and who am I to change long-standing traditions?)

If you right-click, save as file this link, you should get a tid.c .
("tid" is "time", btw. Didn't bother to correct the filename after naming it in norwegian.)

Completely off-topic: Yay! I've got no less than thee RMA'd hard drives on their way back to me. Two from the webshop, the third from WD. (Just inside WD's 3-year warranty. It expires the 16th.)

Sleep, yes. Good idea. (I'm easily distractable.)
 
I'm from northeast Texas and like you we always talk about the weather...mainly how hot it is right now! The saying when in Texas "Wait five minutes and the weather will change!" I live in a small town, but I love Texas and wouldn't ever want to live anywhere else...visit a few place, yes!

Thanks for the link for that file!

Yeah I thought my hdd would last forever, but then I started to download stuff and the 70 gigs I had on my hdd suddenly shrunk to 20 in a time span of a few days..now I dream of terabyte raid setups!

As for distractions...yes, that happens to me all the time as well! Anywho, talk to you tomorrow.
 
Back
Top