This should work the same on a server install as on a desktop with network manager removed. I haven’t much familiarity with the network manager to tell you how to do it via that.
I had an Ubuntu-Desktop installation that I switched to an Ubuntu-Server installation, and I’ve placed it quite a bit away from the nearest router.
So rather than running cables I plugged in an old USB wifi dongle and started looking at how to get it set-up and connected at boot. My installation is on a headless machine (no keyboard, no monitor) so getting this right was important as I would have no other way to connect into the box and debug it / fix it.
I started off by testing out wpa_supplicant as the router needed a WPA paraphrase.
sudo apt-get install wpa_supplicant
Then, to get the paraphrase into a key that this utility can use, I copy the output from wpa_passphrase into a config file and test :
wpa_passphrase network password
network={
ssid="network"
#psk="password"
psk=e2e04dcb82891a286e5d524b63f4963ac1f8dc49852bd6b97441d9545054d270
}
wpa_passphrase network password >; wpa-test-config.cfg
Before testing I checked the WPA support and driver info:
hwinfo --netcard
Pay attention to the lines about Driver* and WLAN* – the latter will give you info about what is supported. I didn’t do much with the driver info describing which module controls my card, but I guess it would be useful for debugging.
The WLAN encryption modes my device supported are :
WLAN encryption modes: WEP40 WEP104 TKIP CCMP
which equates to web 64, wep 128, wpa tkip and wpa aes I think (thanks to http://bernaerts.dyndns.org/linux/230-ubuntu-setup-wifi-commandline )
;
Now to test:sudo wpa_supplicant -iwlan0 -cwpa-test-config.cfg -Dwext
I noticed initially that my device was connecting to the node, but kept getting disconnected, and would reconnect. I saw lots of messages like this….
CTRL-EVENT-DISCONNECTED basssid=MAC reason=0
and after finding lots of possibilities from unsupported hardware to buggy-as-heck drivers, I found that for me this was simply because something called network manager was running. (ubuntu server 12.04, was originally an ubuntu desktop install)
Removing Network MaagerSo naturally I did an sudo apt-get remove on that, and then the box los network connection !
So, a monitor borrowed and I can fix it, but to you I just suggest that before removing network manager, if you machine is headless or remote, first ensure that the network will come up without the network manager !
While I was setting up the box I was internet-connected via a LAN cable, so just adding my LAN port (eth0 for me) to auto network configuration on boot brought me back to a place where I can ssh into the box and continue.
I updated /etc/network/interfaces to :
auto lo iface lo inet loopback # added to bring up eth0 (my lan port) and set it up to get an address automatically # ifconfig can help you find which ethx / wlanx you need to add here. auto eth0 iface eth0 inet dhcp
I guess you could kill network manager and restart-network [if that doesn't restart network manager
] or perhaps create a script to temporarily get rid of it :
# pseudo code for script to temporarily remove network manager # - remove network manager sudo apt-get remove network-manager # - restart /etc/init.d/networking restart # - sleep for a period of seconds / minutes. gives you a chance to # verify you can still connect sh -c "sleep 120" # - revert the network (reinstall network manager and restart) sudo apt-get install network-manager /etc/init.d/networking restart
Something like thiat will hopefully let you re-connect if it doesn’t work without network manager ?
Testing againNow that my network works on LAN without network manager, I retest the wireless connection with wpa supplicant per above, and it connects fine.
Mannually calling dhclient wlan0 gets me an ip-address so I’m happy out.
I update /etc/network/interfaces to include the wlan0 interface in auto start and getting an ipaddress via DHCP, but it also needs the above call to wpa_supplicant to get connected to the wireless base station first.
Having been burnt earlier removing network manager, I backup the known-good version of /etc/network/interfaces and write a script to let me test changes to it temporarily, and then revert to the know good.
If the test-changes have worked, I can roll them into the know-good version of the config.
If not, reverting to the know-good config means I don’t have to again go finding a monitor for my headless machine!
The script :
cat test-network.sh #!/bin/bash # first make sure /home/me/network/interfaces.safe is a known-good working config!! # copy /network/interfaces to /home/me/network/interfaces.test and edit, # then run this script to test. # copy over test config and restart nw to test cp /home/me/network/interfaces.test /etc/network/interfaces /etc/init.d/networking restart # let the new config stay for a while for checking sh -c "sleep 30" # revert for safety # replace the live config with the backed-up known-good config and restart nw to activate cp /home/think/network/interfaces.safe /etc/network/interfaces /etc/init.d/networking restart # if it didn't work, edit the test conf and run again # if it did, consider replacing the known good version(.safe) with the tested-good version(.test)The config – Auto start Wireless on boot up
My known-good version of the interfaces config, with the now tested-good wireless config, looks like this :
auto lo iface lo inet loopback auto eth0 iface eth0 inet dhcp auto wlan0 iface wlan0 inet dhcp pre-up wpa_supplicant -B -Dwext -iwlan0 -c/etc/wpa-supplicant.conf
So, for a Gnu/Linux install recently I had a CD with Ubuntu – but it was the desktop edition.
I have an old box for this install, and I really needed the CD with the ubuntu-server install set by default.
What to do ?
As it turns out, it’s actually quite easy to switch over from the desktop install to the server, and vice versa.
So, after installing from the desktop CD, Ubuntu Gnu/Linux is set up with the alias package ubuntu-desktop which (for v 12.04 at least) gives us the gnome desktop, libre-office and a host of other stuff.
To remove the desktop bits, you can try to figure out what was installed, and do a
sudo apt-get remove packagex packagey packagez
to get rid of them, but I found this alternative using tasksel that bit more elegant and time friendly :
# ubuntu desktop -> server
sudo apt-get install tasksel
sudo tasksel remove ubuntu-desktop
# optional # sudo tasksel install server # or ubuntu-server ??
# read somewhere online that there's no difference from server and
# desktop kernels anymore, but did this anyway
sudo apt-get install linux-server linux-image-server
That was it!
I was recently trying to find out how to automatically set the date on a windows machine(windows XP, but solution here should be generic I think).
I tried using the system date and time setting “Automaticall Update Time”, but that failed.
Contrary to this info from MS (http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/windows_date_it_overview.mspx?mfr=true) it would not update the time as the date was wrong/different.
Anyway, that seems to only sync once a week. I need a way to set / reset the system time automatically, every time the computer starts.
The reason for all of this is that :
- The clock battery in the PC (a very cheap third hand pentium p4 ) is gone.
- The attachment for it is broken so there is no option to replace.
- The power to the PC is cut regularly at night so the machine loses any previous date/time setting.
- The correct date / time is required for connecting to secure web sites ( ask certs are date/time limited ) so it needs to be correct for happy internet browsing.
- manually setting it is extra hassle for the non-techie user, and onerous to do every time the machine is started
Finding no other system workarounds, it was time obviously to throw a script together!
I soon found an Ntp package library in Perl that would take care of all the connecting to Ntp servers etc, but had a problem with a activestate Perl installation.
The ruby language has such a package also (http://rubygems.org/gems/net-ntp), and I had no issues with the installer from http://rubyinstaller.org/ as suggested from http://www.ruby-lang.org/en/downloads/
Firing up a text editor I saved the following as c:\scripts\ruby-test.rb and ran it with ruby c:\scripts\ruby-test.rb from a cmd prompt.
# Here's the code:
puts "Hello there!"
To install the ntp library to do the heavy lifting, type this into a cmp prompt
gem install net-ntp
In another text editor save the following as c:\scripts\update-system-time.rb. It simply calls to the internet for the date and time (using a public time server) and then uses windows command line commands to set the computer clock the the correct date and time for today.
require 'net/ntp'
Net::NTP.get('1.us.pool.ntp.org') t = Net::NTP.get.time
# set the date via the windows date command system("date #{t.day}-#{t.month}-#{t.year}") # set the time via the windows time command system("time #{t.hour}:#{t.min}:#{t.sec}")
Setting the wrong date/time and then running this script with ruby c:\scripts\update-system-time.rb proved it works (Oh, it doesn’t work ? Does the account your using have administrator rights ?)
To run it at boot up, I did’t bother with registry settings or anything like that. I just created a batch file to run the script and saved it as c:\scripts\set-time.bat
rem set the time as the motherboard has no clock battery
ruby c:\scripts\update-system-time.rb
Then create a scheduled task to run on startup.
In the control panel click “Schedule Tasks“. Click “Add scheduled task“. In the pop-up “Scheduled Task Wizard” click browse and locate and select the batch file c:\scripts\set-time.bat
Give it a name, and for the “Perform this task:” option select “When my computer starts“.
Next you will have to give it a user name and password so it can run. You may need to run this as a user with admin rights in order change the date/time. (I did use an account with administrator rights for the task and testing).
That was it, the computer is unplugged regularily at which point the bios and clock are reset, the clock to sometime in 2001. But when the machine eventually boots up, this little script is run and the clock is updated from the internet.
Happy browsing!
In processing some XML into an SqlServer db it can often be useful to have the element name or the parent element name, depending on how your xml data is organised.
Below is an example of using meta properties in MS SQL Server for just this purpose..
DECLARE @RESPONSE XML
DECLARE @XmlDocumentHandle int
set @RESPONSE = '
name1
desc 1
name2
desc 2
'
PRINT '**DEBUG ** : Preparing xml doc for response.'
EXEC sp_xml_preparedocument @XmlDocumentHandle OUTPUT, @RESPONSE
select *
from OPENXML (@XmlDocumentHandle, '/frag/foos/*/bar', 2)
WITH (
whichFoo varchar(50) '@mp:parentlocalname',
whichBar varchar(50) '@mp:localname',
bar_name varchar(50) 'name',
bar_desc varchar(50) 'desc'
) AS foobars
-- Remove the internal representation.
EXEC sp_xml_removedocument @XmlDocumentHandle
Results
whichFoo WhichBar bar_name bar_desc
foo1 bar name1 desc 1
foo2 bar name2 desc 2
It is worth noting perhaps that these to meta properties can only be used in the context of the root element as specified by the path in the Openxml function call.
You can’t for instance retrieve the value of “whichBar” from the above example by doing something like
nameParent varchar(50) 'name/@mp:parentlocalname'
In my case I just altered the xml to have a different/better(?) structure, but still in future I’m sure I will find a use for this.
If you are using SQL Server Managment Studio to connect to various database servers, and these servers have a naming convention that is not intuitive to you, you may be frustrated trying to quickly recall what server connection is for what just by having a glance.
The “Connect To Server” dialog that is presented when you open a new query or want to connect a query to a DB to run it offers no way to enter an alias for the server name.
In this case, should you wish to list your servers by names more meaningful to yourself, and even group them by use perhaps, then the “Registered Servers” view (CTRL-ALT-G or under the View menu) is definitely worth a look.
You can “register” servers under a “server group”, which essentially amounts to giving the server name and your authentication, but importantly here you can replace the server name with a new name – an alias. I prepend my alias so I still have the server details visible at a glance.
In addition, you can also add sub-groups which can be handy for keeping logically related servers together for faster access.
Lastly, you can export the list for import to other machines by right-clicking on the Server Group and chosing export from under the “Tasks” (part of my backups now!)
More detail at http://msdn.microsoft.com/en-us/library/ms188231.aspx
Frustration with the tail command this morning on a box running Sun OS.
I couldnt get it to tail a specifieed number of lines of a large text file.
On gnu/Linux I might use something like:
tail -n 50 my.log
On sunOs that command failed, and nothing else I try seems to work.
A search of available tail commands shows up a few hits
find /usr -name tail2>/dev/null
/usr/bin/tail
/usr/xpg4/bin/tail
...
And the result at
usr/xpg4/bin/tail works just like the gnu equivalent.
/usr/xpg4/bin/tail -n50 my.log
FWIW I’m on a box with SunOS 5.10 atm.
So, you want to run a query in sql server and get the output into a fixed record format flat-file / flatfile?
This solution involves some manual process and the use of excel (though other spreadsheet software may work as well).
There are solutions you can use on windows with command line utilities for SQL server like BCP and sqlcmd.exe, but I think they require padding with spaces and then trimming to a specified length, which you may well be fine with doing.
If you are looking to have a repeatable solution you may have more performance and less headache by using a programming language or scripting language to read the data and create the output in the desired format.
When i say flat-file i mean without character(s) reserved for delimiting like with commas in a .csv file, or tab or vbar(|) etc. as is often the case.
If you’re working with mainframes you may think of RECFM=FB, so LRECL is going to be the same for all records.
- Run your query in SQL server with “Results to grid” option selected
- Copy the output to excel
- Select a column, right click the column header, select “column with” and set to desired length
- Repeat for all cols
- select File -> Save as -> Formatted text (space delimited) (*.prn)
- save your file – this is your fixed record format flatfile!
That’s it, a little manual intervention with excel and you can easily save you data to a flatfile witouth delimiters.
I have found this very useful for generating once off reports.