Visit Our UNIX and Linux User Community


I could use some help with making a script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting I could use some help with making a script
# 1  
Old 08-07-2013
I could use some help with making a script

I run a small instrument lab. We track our user's time on the instruments with a very manual process of 'last wtmp.1' then cut/paste data into spreadsheets. My boss makes the initial spreadsheets then I convert and format them for uploading into our billing software (COReS). Cores is looking for a very specific set of data for each 'charge' in a csv file.
Code:
Primary Comments,Customer Account Number,Transaction Date,Service Description,Quantity,Unit,Price,Service Category,PI's Name,Purchaser's Last Name,Short Contributing Center Name,Resource Name,Line Item Assistant,Line Item Comments

And each "order" is like this-
Code:
600 NMR,201895**********,07/31/13,600 MHz,34.97,Hour,6,600 MHz,Ash,Ash,"""""",600 NMR,"""""",""""""

Currently I get instrument usage data from a small perl script (@ pastebin.com/Zu5pwXHK ) and wtmp. All of our workstations are either Red Hat or CentOS. It's output is-
Code:
  dronnow 40
  dwright3 272
  esoto1 52
  ewhite5 36
  gliu3 327
  gshaw1 382

I'm looking for something that will take our users time on the instrument, add their supervisor (the ASH entry's above) and account number (201895**********) then output all that data into a csv file suitable for uploading into Cores. Any clue where to start?
# 2  
Old 08-07-2013
Don't understand. Pls show input and desired output and explain the logics to get from one to the other.
# 3  
Old 08-07-2013
Thanks for the fast reply!

Input is from the various workstations that users log into, via that perl script. It outputs the username and time in minutes,
Code:
  dronnow 40
  dwright3 272
  esoto1 52
  ewhite5 36
  gliu3 327
  gshaw1 382

I will make another csv file with their details having
Code:
username,supervisor,account_number
dwright3,Creary,327531**********
gliu3,Miller,330198**********

I would like something that takes the user login time and adds each individuals account_number and supervisor, plus what instrument/workstation the time was on (different rates for different instruments). This can probably be accomplished by setting the first variable ($1=Bruker_600) or something.

Output must be like this with a header then usage charges:
Code:
Primary Comments,Customer Account Number,Transaction Date,Service Description,Quantity,Unit,Price,Service Category,PI's Name,Purchaser's Last Name,Short Contributing Center Name,Resource Name,Line Item Assistant,Line Item Comments
600 NMR,201895**********,07/31/13,600 MHz,34.97,Hour,6,600 MHz,Ash,Ash,"""""",600 NMR,"""""",""""""
600 NMR,327531**********,07/31/13,600 MHz,25.25,Hour,6,600 MHz,Creary,Creary,"""""",600 NMR,"""""",""""""
600 NMR,261485**********,07/31/13,600 MHz,33.55,Hour,6,600 MHz,Helquist,Helquist,"""""",600 NMR,"""""",""""""
600 NMR,330198**********,07/31/13,600 MHz,11.48,Hour,6,600 MHz,Miller,Miller,"""""",600 NMR,"""""",""""""

---------- Post updated at 12:57 PM ---------- Previous update was at 12:55 PM ----------

I should add, this only needs to be done once a month. The perl script will run at 0001 on the 1st of the month for last months login data, eg wtmp.1
# 4  
Old 08-07-2013
I still can't see how to get from one to the other. Where is dwright3's 272 ? Where do the other data come from? Are they constants?
# 5  
Old 08-07-2013
Yes, every month the perl script is run outputting

Code:
dwright3 272
esoto1 52
ewhite5 36

Then I need to combine that data with account information (doesnt change, constant)-
Code:
dwright3,Creary,327531**********
etc
etc

to finally get an output.csv that I can upload to our billing software like this
Code:
Primary Comments,Customer Account Number,Transaction Date,Service Description,Quantity,Unit,Price,Service Category,PI's Name,Purchaser's Last Name,Short Contributing Center Name,Resource Name,Line Item Assistant,Line Item Comments
600 NMR,201895**********,07/31/13,600 MHz,34.97,Hour,6,600 MHz,Ash,Ash,"""""",600 NMR,"""""",""""""

---------- Post updated at 01:22 PM ---------- Previous update was at 01:14 PM ----------

OHHH!! Maybe the output file is confusing, since it's not representative of the data given.

A sample of the output for dwright3 would be

Code:
600 NMR,327531**********,07/31/13,600 MHz,4.53,Hour,6,600 MHz,Creary,dwright3 ,"""""",600 NMR,"""""",""""""

# 6  
Old 08-07-2013
Again, what about dwright3's 272 coming from your perl script?
# 7  
Old 08-07-2013
Code:
username  time_in_minutes
dwright3 272
esoto1 52
ewhite5 36

The time gets put into the Quantity field of the output.csv

Previous Thread | Next Thread
Test Your Knowledge in Computers #466
Difficulty: Medium
NTP was designed by David L. Mills of the University of New York.
True or False?

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Help me making this script

This script is executed whenever a new vehicle is added to the cycle-motor park of campus. The script asks for the following information about the car and adds a new line to the vehicle file.txt: name (name of an animal, unique identifier), color, mark, model, type (e.g., electrical, manual),... (2 Replies)
Discussion started by: andre2222
2 Replies

2. AIX

Making a trace for a script

Hello experts, I'm trying to make a trace (unix log) in hope to see why I have differences in some bases : I putted at the first { and in the last line } > $DATA_SAS 2>&1 Is it a right command ? Do you have another solution ? thank you, regards, (7 Replies)
Discussion started by: rimob
7 Replies

3. Shell Programming and Scripting

Making any script executable

Hi all, I'm new to Unix so just wanted some help. I've been self learning and came accross a question online that I was trying. It is to make any shell script executable, the name of the file is to be made executable. I would use nano and type in something like #! /bin/bash Chmod +x... (4 Replies)
Discussion started by: HelenaR
4 Replies

4. Shell Programming and Scripting

Need Help With making this script

Hello, im a new user on this site and learning scripting very slowly at a understanding pace. However i am up with a challenge and require help completing this. The script has to include arguments, variables, decisions and loops. So the script is about calculating the broadcast address for any... (5 Replies)
Discussion started by: tHe666
5 Replies

5. Shell Programming and Scripting

Help making a tasklog script

I am trying to create a program called tasklog that integrates with one of my online accounts, to keep track of what tasks I have been working on. On login, I'd like it to display (up to) the five most recent entries, then ask me what I plan to work on during the new session. I then will type an... (3 Replies)
Discussion started by: santod
3 Replies

6. Shell Programming and Scripting

making shell script

Hi , I am new to shell scripting I want to make script as to execute followng command mysqldump -u (user name) -p(password) database name>filename.sql this file saves with current date and time and execute automatically at particular time which I give (10 Replies)
Discussion started by: kaushik02018
10 Replies

7. Shell Programming and Scripting

making script

hello experts cany any one help me i want to make one script which can rlogin to another machine . but it should not ask me username/password from me of another machine it should take the username and password from the script only. please help me out. regards, shary (2 Replies)
Discussion started by: shary
2 Replies

8. Shell Programming and Scripting

Need help making a script

Here is what I have: #!/bin/bash # Setup year date and month YR=`date +%Y '{print $6}'` MON=`date +%b '{print $2}'` DAY=`date +%d '{print $3}'` file=$YR$MOY$DOM # clear # Dump database using USER/PASS to ..sql mysqldump --user=me -ppass database > database-db.$file.sql The YR, MON and... (2 Replies)
Discussion started by: npereira
2 Replies

9. Shell Programming and Scripting

Making flags for my script

I have no idea how to make my own flags. (6 Replies)
Discussion started by: rcunn87
6 Replies

10. Shell Programming and Scripting

Making a script exectuable

Hi, I'm pretty new to Unix and I just have a question concerning making a script executable without putting the "sh" command before it. In case it makes the difference I am on an Apple computer using the Terminal. Anyway here is the little test code I wrote followed by the commands I took to try to... (5 Replies)
Discussion started by: BuyoCat
5 Replies

Featured Tech Videos