Information Technology Services: Web

Working with Form to File data


Creating, re-creating your data file and fixing your data file permissions

Creating and re-creating your data file

If you need to create or re-create your data file run the command mkdat which was previously called setacl.bsh. The mkdat command currently lives in the non-standard directory /home2/c/w/wwwdev/bin or just ~wwwdev/bin.
Note: the command has been modified to accept a starting directory outside of your HOME directory which will be termed the "data file HOME directory" or just "data HOME."
You must have write access to the directory you provide as your data HOME.
Usage: mkdat [data_HOME]
(where brackets indicate optional parameters).

The mkdat command is interactive and will prompt you for the sub-directory within your data HOME directory where you would like your data file placed. It will not overwrite an existing directory or data file.

For example initially running:
~wwwdev/bin/mkdat    /www/prod/some_site_dir
places you in the /www/prod/some_site_dir directory and prompts for a sub-directory name to be created within this directory. Upon successful completion of mkdat you should have a directory for your data file created within /www/prod/some_site_dir and an empty data file within this directory.

The default and typical behavior of mkdat has been left unchanged and when run without providing a data HOME directory will assume data HOME is the account's HOME directory.

You will then be prompted for the name you wish to give your data file. It will not overwrite an existing file. However, it will ensure the file is accessible to the web server.

If the file does not exist, it will create the file and ensure the file is accessible to the web server.

The process will repeat until you enter 'q' to quit the program. This will allow you to create multiple directories and/or data files for multiple forms.
Please note: Although you can create multiple Form to File data files, only those which have been registered will function. Consequently, the directory name and data file name you provide to the mkdat script must be the same as those entered in the registration form.

On exit from the program, e-mail will be sent to the administrator. This e-mail will contain a record of any directories and files you created with mkdat. You may be contacted if the directory names and files you create using mkdat do not match the names you requested on the registration form.

Fixing your data file permissions

One of the tasks mkdat handles is setting the permissions on the data file to allow the web server to write to the file. It does this by setting an ACL (access control list) on the file giving the web server write permission. Occassionally this ACL gets removed. For example, opening your data file in Emacs will remove the ACL.

To reset the ACL on your data files simply run mkdat script again and provide the existing directory and data file names. The mkdat command will not re-create an existing file. It will simply adjust the permissions to allow the web server write access.

To avoid the issue with the ACL follow the guidelines in the section "Retrieving and viewing your data files."

Retrieving and viewing your data files

Viewing the contents of a data file

Warning: a problem has been discovered when using Emacs to view your data files. Emacs will remove the ACL set on your data file. This will prevent the web server from writing the data from your HTML form to your data file.
Tested alternatives:
the pico editor, using the view option in WS FTP. Using the less, more, cat, tail commands are fine also. Tips for using cat, more, tail and the mvdat command are included below.

Methods for retrieving and viewing your data files

The steps outlined below describe working with your data file from the UNIX environment. If you wish to work with your file on a personal computer you should transfer the file to your computer using an FTP client. The file can then be imported into any program which supports importing of text data, or you can simply open the file in a text editor to view the data.

Methods for working with your data files:

  1. All at once--
    Assumption; You have all the data you wish to collect and you will not be using your HTML form again.
    1. Remove or disable your HTML form.
    2. Copy or transfer your data file to a working area (another UNIX directory, a personal computer, etc...).
    3. Evaluate your data in raw form or import into the application of your choice.
    4. Remove the data file if you no longer need it.
    5. Notify wwwreq@albany.edu that you are finished using the Form to File service so we may remove you from our registration file.
  2. All at once periodically--
    Assumption; You wish to periodically remove the data for evaluation, leaving an empty file for future entries.
    1. Move your data file's data to a new file and zero out the data file by running:
      ~wwwdev/bin/mvdat data_file data_file_copy
      Example: ~wwwdev/bin/mvdat survey.txt survey_data.txt
      Result: creates a new file, survey_data.txt, containing the data from survey.txt.
      Data from the original file, survey.txt, is removed leaving an empty file.
    2. Evaluate your data in raw form or import into the application of your choice.
    3. Wait for new data and repeat.
      E.g. ~wwwdev/bin/mvdat survey.txt survey_data2.txt
      Note: If you wish to keep a running history of data make sure you give each [data_file_copy] a new name. In the case above I would use mvdat to copy my initial data to survey_data.txt. For any following data submitted to survey.txt I would use mvdat to copy the newer information to a file called survey_data2.txt.
      Tip: To create a combined copy of your separate files you can use the UNIX "cat" command.
      E.g. cat survey_data.txt survey_data2.txt > survey_combined.txt
  3. All new data periodically--
    Assumption; You wish to periodically work with only new data while leaving all the data in your data file.
    1. From the beginning of the file, determine line number where your new data starts..
      Use the "number line" command with the more command: /usr/bin/nl -ba data_file ¦ more
      where -ba indicates the nl command should number all lines, and
      the "¦ more" prevents the data from scrolling off the screen (use the space bar to move forward one page at a time, 'q' key to quit and 'h' key for additional help).
      For Example:
      nl -ba survey.txt ¦ more
    2. After determining the first line number where your new data starts, use the tail command to extract the data starting at a given line number.
      Usage:
      /usr/bin/tail [+linenum] [data_file] (this will display the data on the screen to preview it) and
      /usr/bin/tail [+linenum] [data_file] [ > outfile] (this will write the data to outfile).
      For Example:
      /usr/bin/tail +22 survey.txt > surveynew.txt
      would write lines from the file survey.txt starting at line number 22 to a file surveynew.txt.

Form to File Introduction

University at Albany homepage