Linux - SoftwareThis 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
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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?
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.
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
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?
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.
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.
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.
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?
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.
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?
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.
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.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.