LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 09-02-2009, 03:41 PM   #1
miros84
Member
 
Registered: Aug 2009
Location: Spain
Distribution: Debian stable, squeeze
Posts: 501

Rep: Reputation: 31
Can I use funcion in terminal?


Hello
I am looking for some functon that I can use in terminal. Funcion that generate numbers
or letters.
Example: If I copy I file copy file this way:

Code:
tar -zcvf /media/Multimedia/newexpbackup/01.backup.tar.gz /home/miros/Myboxfiles
in this case the output file will be named
Code:
01.backup.tar.gz
but I want to be with random name. it is possible do that?
 
Old 09-02-2009, 03:53 PM   #2
tredegar
LQ 5k Club
 
Registered: May 2003
Location: London, UK
Distribution: Debian "Testing"
Posts: 6,119

Rep: Reputation: 416Reputation: 416Reputation: 416Reputation: 416Reputation: 416
Quote:
but I want to be with random name. it is possible do that?
Of course it is.

What have you read / researched or tried?

What isn't working for you?
 
Old 09-02-2009, 04:14 PM   #3
i92guboj
Gentoo support team
 
Registered: May 2008
Location: Lucena, Córdoba (Spain)
Distribution: Gentoo
Posts: 4,083

Rep: Reputation: 404Reputation: 404Reputation: 404Reputation: 404Reputation: 404
There's a $RANDOM variable that you can read from, it will provide a 4 cipher random number.

Code:
tar -zcvf "/media/Multimedia/newexpbackup/$RANDOM.backup.tar.gz" /home/miros/Myboxfiles
Is that enough randomization or do you require something more complex?
 
Old 09-02-2009, 04:39 PM   #4
miros84
Member
 
Registered: Aug 2009
Location: Spain
Distribution: Debian stable, squeeze
Posts: 501

Original Poster
Rep: Reputation: 31
Oo, great great great. I see here in this forum there are people that understund bash comand.
I tried that

Code:
$imefile='(date)' | mkdir /media/Multimedia/newexpbackup/'$imefile' | tar -zcvf /media/Multimedia/newexpbackup/'$imefile'/backup.tar.gz /home/miros/Myboxfiles
What I want is create a folder with difirent name depend on the date. But instead of that, it creat a folder named $imefile
So, I understund my comaand is wrong. Can you check it please?

$random is OK. I tested and everyting is all right.
Will be better if I can do it with date names.

Last edited by miros84; 09-02-2009 at 04:45 PM.
 
Old 09-02-2009, 05:12 PM   #5
i92guboj
Gentoo support team
 
Registered: May 2008
Location: Lucena, Córdoba (Spain)
Distribution: Gentoo
Posts: 4,083

Rep: Reputation: 404Reputation: 404Reputation: 404Reputation: 404Reputation: 404
Quote:
Originally Posted by miros84 View Post
Oo, great great great. I see here in this forum there are people that understund bash comand.
I tried that

Code:
$imefile='(date)' | mkdir /media/Multimedia/newexpbackup/'$imefile' | tar -zcvf /media/Multimedia/newexpbackup/'$imefile'/backup.tar.gz /home/miros/Myboxfiles
What I want is create a folder with difirent name depend on the date. But instead of that, it creat a folder named $imefile
So, I understund my comaand is wrong. Can you check it please?
There are a couple of important errors in that code.

You probably want "imefile=$(date)", note that to assign a value to a variable you don't use "$var=", just "var=". Note also that the command expansion is $(...), and not just the parentheses. Even more, you might want to try to specify a proper format for the date, instead of the default output for date. Like this:

Code:
imefile=$(date +"%Y%m%d%H%M")
The other part of the pipe has one big problem: you are using single quoting on the var name. Unlike double quoting "...", single quoting '...' prevents the expansion of variables. Whatever goes in between '...' is a literal string, and will be taken as-is without any further expansion. Double quoting serve the purpose of delimiting the string while retaining the capacity to use var expansion, which is what you need here.

Last, but not least, the purpose of pipes | is not to concatenate commands that way. Pipes are used to the commands at the right side can use the output of the command at the left side as its input.

So, putting it all together you probably want this:

Code:
imefile=$(date +"%Y%m%d%H%M"); mkdir "/media/Multimedia/newexpbackup/$imefile"; tar -zcvf "/media/Multimedia/newexpbackup/$imefile/backup.tar.gz" /home/miros/Myboxfiles
 
Old 09-03-2009, 01:42 AM   #6
miros84
Member
 
Registered: Aug 2009
Location: Spain
Distribution: Debian stable, squeeze
Posts: 501

Original Poster
Rep: Reputation: 31
Tnank you i92guboj for helping. I am learning all this you xplain here. I use this comand for ghnome schedule program meybe you know. And when I put % in the comand, it didnot accept it.
Any advice?
And can you tell me waht kind of program language I need to learn to can write coamnds? Can you give me some wiki guide or manual to learn more?
 
Old 09-03-2009, 02:31 AM   #7
i92guboj
Gentoo support team
 
Registered: May 2008
Location: Lucena, Córdoba (Spain)
Distribution: Gentoo
Posts: 4,083

Rep: Reputation: 404Reputation: 404Reputation: 404Reputation: 404Reputation: 404
Quote:
Originally Posted by miros84 View Post
Tnank you i92guboj for helping. I am learning all this you xplain here. I use this comand for ghnome schedule program meybe you know. And when I put % in the comand, it didnot accept it.
I don't know much about gnome, it's been years since I used it the last time. I guess that you want to use some kind of scheduler to do a periodic task with the command I gave you above. If that's true, I'd rather look into using cron for the task (maybe the program you speak of is a frontend to cron...).

Quote:
And can you tell me waht kind of program language I need to learn to can write coamnds? Can you give me some wiki guide or manual to learn more?
Learning a bit of shell scripting will be helpful. The shell is the program that prints the prompt, read the commands that you write and interprets them. In most distributions this is by default "bash". There are many more, but bash is the default shell nowadays for most Linuxes.

I suggest you to pick the Advanced Bash Scripting Guide. Don't be afraid, regardless of the title it's perfectly suitable for beginners (and when in doubt there's always this forum). Learning more about bash and how it works, and about the general and well known command line tools, will probe very useful when dealing with the command line.
 
Old 09-03-2009, 04:50 AM   #8
miros84
Member
 
Registered: Aug 2009
Location: Spain
Distribution: Debian stable, squeeze
Posts: 501

Original Poster
Rep: Reputation: 31
Thank you for help.
So, I have to open this file: crontab in my Linux and add the comand?
Can you please give me only one example of the comand above, what exactly I have to add it, to execute it every minut or every week?
I used this program with GUI http://gnome-schedule.sourceforge.net/ and was easy. Just I can select every day or every week and input the comand.

Last edited by miros84; 09-03-2009 at 04:52 AM.
 
Old 09-03-2009, 05:26 AM   #9
i92guboj
Gentoo support team
 
Registered: May 2008
Location: Lucena, Córdoba (Spain)
Distribution: Gentoo
Posts: 4,083

Rep: Reputation: 404Reputation: 404Reputation: 404Reputation: 404Reputation: 404
You could use crontab, yes, however it might be easier to just put your custom script into one of the /etc/cron.* directories. For example, to run your script once a week you could put it in /etc/cron.weekly/. You would just need to put the commands inside a file on that directory and then chmod u+x it, so it becomes executable.

To see the full documentation for the crontab config file you can use "man 5 crontab", "man crontab", without the 5, will show you the man page for the tool, not the config file.
 
Old 09-03-2009, 08:47 AM   #10
miros84
Member
 
Registered: Aug 2009
Location: Spain
Distribution: Debian stable, squeeze
Posts: 501

Original Poster
Rep: Reputation: 31
I tried to use this comand to copy one foler from my PC to another PC, and I didnot have luck.

Code:
imefile=$(date); mkdir "smb://miros-laptop/archivos/copsegexper/$imefile"; tar -zcvf "smb://miros-laptop/archivos/copsegexper/$imefile/backup.tar.gz" /home/miro/
Bash says:

Code:
rsh: Could not resolve hostname smb: Name or service not known
tar: smb\://miros-laptop/archivos/copsegexper/jue sep  3 15\:42\:13 CEST 2009/ba
I have these 2 PCs in home network. I can access to this folder wirh nautilius, I can read and write, but in bash, I can copy. Do you know what is wrong with the comand?
 
Old 09-03-2009, 09:16 AM   #11
i92guboj
Gentoo support team
 
Registered: May 2008
Location: Lucena, Córdoba (Spain)
Distribution: Gentoo
Posts: 4,083

Rep: Reputation: 404Reputation: 404Reputation: 404Reputation: 404Reputation: 404
That's not the way that linux works. If you want to access that way a samba or cifs share in the command line, you first need to properly mount it on your filesystem, then you can access them like any other directory that lives physically in your computer.

I rarely use cifs or samba, so I have no idea about the syntax right now. But it's like mounting a cdrom, once you mount the remote share you can just cd into it, use tar or whatever. Those commands have no notion of smb://, that's just something that gnome and kde invented and are not part of linux. Desktops usually do this kind of thing, wrongly in my opinion because they hide the true nature of the things, and then the user gets confused as soon as they try to go a bit deeper like in your case.

You should be able to mount the share with either mount.cifs, mount.samba, or simply mount with -t smbfs or -t cifs. Is all I can tell you right now, as said, I rarely use samba or cifs at all.

Last edited by i92guboj; 09-03-2009 at 09:17 AM.
 
1 members found this post helpful.
Old 09-03-2009, 09:49 AM   #12
miros84
Member
 
Registered: Aug 2009
Location: Spain
Distribution: Debian stable, squeeze
Posts: 501

Original Poster
Rep: Reputation: 31
Do you mean I have to mount it as I have to mouunt some partition on my computer?
I use mint and when I access some partition, it is mounted automaticly, so I suppose it is monted yet. If so, in which directory it is mounted? DO you know?
 
Old 09-03-2009, 09:57 AM   #13
i92guboj
Gentoo support team
 
Registered: May 2008
Location: Lucena, Córdoba (Spain)
Distribution: Gentoo
Posts: 4,083

Rep: Reputation: 404Reputation: 404Reputation: 404Reputation: 404Reputation: 404
Quote:
Originally Posted by miros84 View Post
Do you mean I have to mount it as I have to mouunt some partition on my computer?
Yes. In Linux everything is a file hanging at some point from /, including remote shares. It's the only thing that ALL the linux userland tools understand.

So, to use a remote share, you have to attach it to your filesystem, that's what mount does for remote or local volumes. It's all the same.

Quote:
I use mint and when I access some partition, it is mounted automaticly, so I suppose it is monted yet. If so, in which directory it is mounted? DO you know?
That depends on the distro, I know nothing about mint either. I think that the syntax to mount a samba volume is like this:

Code:
mount -t smbfs //WIN_BOX/name_of_shared_resource /mnt/whatever_directory
Where WIN_BOX is the name of the windows machine, "name_of_shared_resource" is the name of the shared folder or whatever, and "whatever_directory" is the local directory where you want to mount the remote share. This directory must exist of course.

If the mount succeeds, you will be able to access the remote share by simply entering /mnt/whatever_directory, without any extra hassle and with any program or command line tool.

This is from memory as said, so I'd rather check the man pages. If you need specific help mounting a remote share using samba, you should open a new thread so you can get better responses than mine. As said, I am not the best one to help with samba or cifs.
 
Old 09-04-2009, 11:26 AM   #14
miros84
Member
 
Registered: Aug 2009
Location: Spain
Distribution: Debian stable, squeeze
Posts: 501

Original Poster
Rep: Reputation: 31
If I put a file in /etc/cron.weekly/
which day and at what time it will execute this command?
 
Old 09-04-2009, 11:37 AM   #15
canyonbreeze
LQ Newbie
 
Registered: Apr 2009
Posts: 18

Rep: Reputation: Disabled
I would think the first minute of the first hour of the first day of the week. I had a problem with the computer bogging down every hour on the hour as too many cron jobs were scheduled simply as 'hourly'. I divided them out at different minute offsets thruout the hour and things run smoothly.

If you're just looking to do a regularly scheduled backup you may try something like...

tar czPf /media/data/backup/etc_backup_$(date +%y%m%d).tgz /etc

This is a line from my daily backup script that runs every night. It creates an archive of the /etc/ directory to a file that has the date appended.

The backup script also includes...

find /media/data/backup/*.tgz -mtime +14 -exec rm {} \;

... which deletes backups older than 14 days. That way I have daily backups for the last 2 weeks and don't fill up the disk.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
How do I resize the terminal window from the command line in the gnome terminal QuIcKSpArK Linux - Newbie 5 04-21-2012 02:04 PM
not screen-blanking in terminal - what sets the idle timeout on monitor for terminal stardotstar Linux - Hardware 2 08-14-2011 05:46 AM
Ubuntu 8.04 Terminal - Can you make the terminal window transparent with a wallpaper? bparkerson04 Linux - Newbie 6 02-17-2009 05:12 PM
Switching back to the Mandrake 9.1 desktop from terminal rdesktop terminal session marc218 Linux - General 6 02-08-2007 02:45 PM
C++ Pointer altered on a member funcion call moyacuba Programming 6 04-02-2004 07:45 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 12:32 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration